\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{The\_one\_and\_only} \pdfinfo{ /Title (python-basics.pdf) /Creator (Cheatography) /Author (The\_one\_and\_only) /Subject (Python Basics Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{F07D00} \definecolor{LightBackground}{HTML}{FEF6EF} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Python Basics Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{The\_one\_and\_only} via \textcolor{DarkBackground}{\uline{cheatography.com/66522/cs/16602/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}The\_one\_and\_only \\ \uline{cheatography.com/the-one-and-only} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 9th August, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Zuordnung von Variablen}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{x = 5 \newline % Row Count 1 (+ 1) print(x) \newline % Row Count 2 (+ 1) {\emph{5}}% Row Count 3 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Ausgaben und Platzhalter sind im Text durch {\emph{kursive Schrift}} gekennzeichnet.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Verschiedene print-Varianten}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{de = "Deutschland" \newline % Row Count 1 (+ 1) de\_pop = 82.67 \newline % Row Count 2 (+ 1) mil = "Millionen" \newline % Row Count 3 (+ 1) de\_cap = "Berlin" \newline % Row Count 4 (+ 1) cap\_pop = 3.47 \newline % Row Count 5 (+ 1) cap = "Hauptstadt" \newline % Row Count 6 (+ 1) {\bf{Typkonvertierung}} \newline % Row Count 7 (+ 1) print("In "+de+" leben "+str(de\_pop)+mil+".") \newline % Row Count 8 (+ 1) {\emph{In Deutschland leben 82.67 Millionen.}} \newline % Row Count 9 (+ 1) {\bf{Benutzung von Kommas}} \newline % Row Count 10 (+ 1) print("In",de\_cap,"wohnen",cap\_pop,mil".") \newline % Row Count 11 (+ 1) {\emph{In Berlin wohnen 3.47 Millionen Menschen}} \newline % Row Count 12 (+ 1) {\bf{Einfügen mit {\emph{.format()}}}} \newline % Row Count 13 (+ 1) print("\{0\}s \{1\} ist \{2\}.".format(de,cap,de\_cap)) \newline % Row Count 14 (+ 1) {\emph{Deutschlands Hauptstadt ist Berlin.}}% Row Count 15 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Datentypen}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{String} & "Hello", 'Night', "20", """Multilines""" \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Integer} & 7, -132, 42 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Float & 7.32, 42.0, - 17.65 \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{Boolean} & True, False \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Typumwandlung}} \tn % Row 0 \SetRowColor{LightBackground} str() & Variable zu string \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} int() & Variable zu integer \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} float() & Variable zu float \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} bool() & Variable zu boolean \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{1.19002 cm} p{0.59501 cm} x{2.79197 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Berechnen von Variablen}} \tn % Row 0 \SetRowColor{LightBackground} x + 7 & 12 & Summe \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} x - 7 & -2 & Subtraktion \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} x * 3 & 15 & Multiplikation \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} x ** 4 & 625 & Potenzierung \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} x \% 2 & 1 & Restberechnung \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} x / 2 & 2.5 & Division \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{5.377cm}}{Kurzschreibweise: x op= y \newline Beispiel: x += 2 erh{\"o}ht x um 2} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.71009 cm} x{0.96071 cm} p{0.71009 cm} x{1.79611 cm} } \SetRowColor{DarkBackground} \mymulticolumn{4}{x{5.377cm}}{\bf\textcolor{white}{Vergleichoperatoren}} \tn % Row 0 \SetRowColor{LightBackground} x \textless{} y & Kleiner & x \textless{}= y & Kleiner gleich \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} x \textgreater{} y & Gr{\"o}{\ss}er & x \textgreater{}= y & Gr{\"o}{\ss}er gleich \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} x == y & Gleich & x != y & Ungleich \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}----} \SetRowColor{LightBackground} \mymulticolumn{4}{x{5.377cm}}{Geben einen boolschen Wert aus} \tn \hhline{>{\arrayrulecolor{DarkBackground}}----} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.78503 cm} p{1.51041 cm} p{1.28156 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Boolsche Operatoren}} \tn % Row 0 \SetRowColor{LightBackground} x and y & x or y & not y \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Bedingungen}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{If Bedingung}} \newline % Row Count 1 (+ 1) if {\emph{Bedingung 1}}: \newline % Row Count 2 (+ 1) ~ {\emph{Anweisung1}} \newline % Row Count 3 (+ 1) elif {\emph{Bedingung 2}}: \newline % Row Count 4 (+ 1) ~ {\emph{Anweisung2}} \newline % Row Count 5 (+ 1) else: \newline % Row Count 6 (+ 1) ~ {\emph{Anweisung3}}% Row Count 7 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Beispiel: \newline if x \textless{} 0: \newline ~ print (" x ist kleiner als null.") \newline elif x == 0: \newline ~ print ("x ist gleich null.") \newline elif x == 1: \newline ~ print ("x ist gleich eins:") \newline else: \newline ~ print ("x ist gr{\"o}{\ss}er als eins.")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Schleifen}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{While Schleife}} \newline % Row Count 1 (+ 1) while {\emph{Bedingung}}: \newline % Row Count 2 (+ 1) ~ {\emph{Anweisung}} \newline % Row Count 3 (+ 1) {\bf{For Schleife}} \newline % Row Count 4 (+ 1) for i in *range(start,end{[}, step{]}): \newline % Row Count 5 (+ 1) ~ {\emph{Anweisung}}% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Methoden für Strings}} \tn % Row 0 \SetRowColor{LightBackground} string.upper() & String zu Gro{\ss}schrift \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} string.lower() & String zu Kleinschrift \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} string.count("x") & Z{\"a}hlt Stringelemente \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} string.strip() & L{\"o}scht Leerzeichen im String \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} string.replace ("x","y") & Ersetzt alle x für y \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Methoden für Listen}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Input}} & {\bf{Output}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \seqsplit{meine\_liste.index(a)} & Index von Element a \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{meine\_liste.count(a)} & Z{\"a}hlt ein Element \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{meine\_liste.append(a)} & Fügt Element a hinzu \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{meine\_liste.remove(a)} & L{\"o}scht Element a \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{meine\_liste.reverse()} & Kehrt die Liste um \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} meine\_liste.sort() & Sortiert die Liste \tn % Row Count 10 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Indexing und Slicing}} \tn % Row 0 \SetRowColor{LightBackground} meine\_liste{[}1{]} & Element mit Index 1 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} meine\_liste{[}-2{]} & Vorletztes Element \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} meine\_liste{[}1:3{]} & Element mt Index 1 bis 3 \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} meine\_liste{[}1:{]} & Alle Elemente nach Index 0 \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} meine\_liste{[}:4{]} & Alle Elemente vor Index 4 \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} meine\_liste{[}:{]} & Kopiert alle Elemente \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Die Indexierung von Listen startet bei 0. \newline Beispiel: \newline meine\_liste = {[} "Eins" , "Zwei" , "Drei"{]} \newline meine\_liste{[}0{]} \newline {\emph{Eins}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Nützliche Funktionen}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{help()} & Zeigt Hilfe zum gesuchten Begriff an \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{type()} & Gibt den Datentyp eines Objektes oder Variablen zurück \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{input()} & Gibt die M{\"o}glichkeit einer Eingabe vom Benutzer \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} len() & Gibt die L{\"a}nge eines Strings, Tupels oder Liste zurück \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{round()} & Rundet einen Float \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} sum() & Gibt die Summe aller Elemente zurück \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} max() & Gibt das gr{\"o}{\ss}te Element zurück \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} min() & Gibt das kleinste Element zurück \tn % Row Count 14 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Exception Handling}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{try: \newline % Row Count 1 (+ 1) ~ {\emph{Anweisung}} \newline % Row Count 2 (+ 1) except ValueError as e: \newline % Row Count 3 (+ 1) ~ print e \newline % Row Count 4 (+ 1) except (TypeError, AnotherError): \newline % Row Count 5 (+ 1) ~ {\emph{Anweisung}}% Row Count 6 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Falls innerhalb des {\bf{try}} ein Fehler auftritt, der zum Abbruch des Programmes führen würde, wird das entsprechende {\bf{except}} ausgeführt.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Jupyter Notebook Beyboard Shortcuts}} \tn % Row 0 \SetRowColor{LightBackground} Strg + A & Alles markieren \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Strg + Z & Undo \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Strg + Y & Redo \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} Strg + Enter & Zelle ausführen \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} Strg + Links & Ein Wort nach links \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} Strg + Rechts & Ein Wort nach rechts \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} Strg + Oben & Gehe zum Zellenanfang \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} Strg + Unten & Gehe zum Zellenende \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Pakete}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Import von Paketen}} \newline % Row Count 1 (+ 1) import numpy \newline % Row Count 2 (+ 1) import pandas as pd \newline % Row Count 3 (+ 1) {\bf{Selektiver Import}} \newline % Row Count 4 (+ 1) from matplotlib import pyplot% Row Count 5 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}