\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{max3l} \pdfinfo{ /Title (python-f-r-beginner.pdf) /Creator (Cheatography) /Author (max3l) /Subject (Python für Beginner 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}{A31C1C} \definecolor{LightBackground}{HTML}{F9F0F0} \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 für Beginner Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{max3l} via \textcolor{DarkBackground}{\uline{cheatography.com/121235/cs/22126/}}} \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}max3l \\ \uline{cheatography.com/max3l} \\ \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 24th March, 2020.\\ 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*}{2} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Variablen}} \tn % Row 0 \SetRowColor{LightBackground} name = Objekt & Zuweisung von Objekten \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} name = Ausdruck & Ausdruck wird ausgewertet und dessen Ergebnis als "name" gespeichert \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Variablen}} sind {\bf{Namen für Objekte}}. Sie werden oft verwendet um Werte zu speichern, auf die man sp{\"a}ter zurückgreifen m{\"o}chte.} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Objekte}} sind {\bf{alles m{\"o}gliche}}. In der Objektorientierung sind beispielsweise {\bf{Exemplare von Datentypen}} und {\bf{Instanzen von Klassen}} Objekte.} \tn % Row Count 12 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Variablen k{\"o}nnen {\bf{global}} oder {\bf{lokal}} sein. {\bf{Globale}} Variablen werden au{\ss}erhalb von Funktionen oder Klassen definiert und sind {\bf{überall}} gültig. {\bf{Lokale}} Variablen sind nur {\bf{innerhalb}} der Funktion oder Klasse gültig.} \tn % Row Count 17 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Ausdrücke}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Berechnung (3*2)} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Funktionsaufruf (func())} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Benennungen ({\emph{variablenName}})} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Diese k{\"o}nnen auch beliebig kombiniert werden.} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.432 cm} x{3.648 cm} x{1.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Datentypen}} \tn % Row 0 \SetRowColor{LightBackground} Integer & {\bf{Ganze Zahlen}} & 2 oder -5 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} String & {\bf{Text}} in Hochkommas & "Hallo" oder "2" \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Float & (Flie{\ss}-) {\bf{Kommazahlen}} & 1.23453 oder 2.0 \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{3}{x{8.4cm}}{} \tn % Row Count 6 (+ 0) % Row 4 \SetRowColor{LightBackground} List & Listen (beliebige L{\"a}nge und Elemente) & \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} {[}1, "Hallo", 3.0{]} & Listen werden von {\bf{{[} {]}}} umgeben und die Elemente durch ein Komma getrennt. & \tn % Row Count 12 (+ 4) % Row 6 \SetRowColor{LightBackground} Dictionary & Weist Werten ({\bf{Keys}}) andere Werte ({\bf{Values}}) zu. & \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} \{"Key1":1, "Key2":"Wert2"\} & Ähnlich zu Listen. Anstelle von {[} {]} wird {\bf{\{ \}}} verwendet und der Wert eines Schlüssel wird mit {\bf{:}} zugewiesen. & \tn % Row Count 22 (+ 7) % Row 8 \SetRowColor{LightBackground} None & Nichts & `None` \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2 cm} x{6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Nutzereingaben}} \tn % Row 0 \SetRowColor{LightBackground} input() & Gibt Eingabe des Nutzers als {\bf{String}} zurück \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} input(\textless{}Text\textgreater{}) & Gibt vor der Nutzereingabe Text aus \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bedingte Verzweigung}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{if}} Bedingung: & Wenn die {\bf{True}} ergibt wird der eingerückte Block ausgeführt. \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{else}}: & Else folgt immer auf eine if-Bedingung und ist optional. Der eingerückte Block nach else wird ausgeführt, wenn der if-Block nicht ausgeführt wurde, \tn % Row Count 9 (+ 6) % Row 2 \SetRowColor{LightBackground} {\bf{elif}} Bedingung: & Steht vor else und nach if. Elif verh{\"a}lt sich wie if, wird aber nur ausgeführt, wenn vorherige if oder elif Bl{\"o}cke nicht ausgeführt wurden. \tn % Row Count 15 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Bedingte Verzweigung Beispiel}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{def test(a): \newline if a == 2: \newline print("a ist 2) \newline elif a\%2 == 0: \newline print("a ist durch 2 teilbar, aber nicht genau 2.") \newline elif a\%3 == 0: \newline print("a ist durch 3 teilbar, aber nicht durch 2.") \newline else: \newline print("a ist nicht durch 2 oder durch 3 teilbar.")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Schleifen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{for variable in range(start, ende, schrittgr{\"o}{\ss}e):} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Die Varible wird immer bei jedem Durchlauf der Schleife aktualisiert. Sie startet bei dem Startwert und bei jedem Durchlauf um Schrittweite erh{\"o}ht. Dabei wird der eingerückte Block jedesmal ausgeführt. Es ist zu beachten, dass wenn die Variable auf den Wert Ende gesetzt wird, der Block nicht nochmal ausgeführt wird.} \tn % Row Count 9 (+ 7) % Row 2 \SetRowColor{LightBackground} range(ende) & = range(0, ende, 1) \tn % Row Count 10 (+ 1) % Row 3 \SetRowColor{white} range(start, ende) & = range(start, ende, 1) \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{} \tn % Row Count 12 (+ 0) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{while \textless{}Bedingung\textgreater{}:} \tn % Row Count 13 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{While-Schleifen führen den eingerückten Block aus, wenn die Bedingung zu True berechnet wird. Dies wird vor jedem Durchlauf überprüft.} \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Funktionen und Rückgabewerte}} \tn % Row 0 \SetRowColor{LightBackground} `def func():` & Definition der Funktion func ohne Parameter \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `def func(arg1):` & Definition der Funktion func mit einem Parameter \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `def func(arg1, arg2):` & Es k{\"o}nnen beliebig viele Parameter verwendet werden \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Parameter}} sind {\bf{Variablen}}, welche zur Laufzeit an übergebene {\bf{Argumente}} gebunden werden und nur innerhalb der Funktion gültig sind.} \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} `func()` & Aufruf der Funktion func ohne Argumente \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} `func(2)` & Aufruf der Funktion func mit dem Integer 2 als Argument \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Funktionen werden durch {\bf{( )}} ausgeführt. Wenn {\bf{Argumente}}, also Werte an die Funktion übergeben werden soll, stehen diese in der Klammer.} \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} `return` & Beendet eine Funktion ohne etwas zurückzugeben \tn % Row Count 20 (+ 2) % Row 8 \SetRowColor{LightBackground} `return 2` & Beendet eine Funktion und gibt den Wert 2 zurück \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} `return name` & Beendet eine Funktion und l{\"o}st name auf \tn % Row Count 24 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{`return`}} beendet eine Funktion und gibt den ausgewerteten Wert des anschlie{\ss}enden Ausdrucks zurück. Falls eine Primitive (Integer, String, Float, ...) dort steht wird diese zurückgegeben.} \tn % Row Count 28 (+ 4) % Row 11 \SetRowColor{white} `var = func()` & Der Rückgabewert (Wert von return) wird in "var" gespeichert \tn % Row Count 31 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.84 cm} x{6.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Ausgeben - Zurückgeben}} \tn % Row 0 \SetRowColor{LightBackground} Ausgeben & Etwas dem Nutzer anzeigen ({\bf{print}}) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Zurückgeben} & Etwas beim Beenden an den aufrufenden übergeben ({\bf{return}}) \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} x{7.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Vergleichsoperatoren}} \tn % Row 0 \SetRowColor{LightBackground} == & Testet auf Wertegleichheit \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} != & Testet auf Werteungleichheit \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textless{}= & Testet ob der Wert links kleiner gleich dem Wert rechts ist \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \textgreater{}= & Testet ob der Wert links gr{\"o}{\ss}er gleich dem Wert rechts ist \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \textless{} & Testet ob der Wert links kleiner als der Wert rechts ist \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} \textgreater{} & Testet ob der Wert links gr{\"o}{\ss}er als der Wert rechts ist \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{== und != funktionieren auch bei anderen Datentypen als bei Integers.} \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}