\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{ProjektSB19} \pdfinfo{ /Title (python.pdf) /Creator (Cheatography) /Author (ProjektSB19) /Subject (Python 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}{FFC70F} \definecolor{LightBackground}{HTML}{FFFBF0} \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 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{ProjektSB19} via \textcolor{DarkBackground}{\uline{cheatography.com/81589/cs/19543/}}} \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}ProjektSB19 \\ \uline{cheatography.com/projektsb19} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 3rd June, 2019.\\ Updated 17th June, 2019.\\ 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*}{4} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Variablen und Strings}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Text ausgeben}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`print("Hello world!")` \{\{nl\}\} \textgreater{}\textgreater{} Hello world!} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Text mit einer Variablen ausgeben}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`msg = "Hello world!" \{\{nl\}\} print(msg)` \{\{nl\}\} \textgreater{}\textgreater{} Hello world!} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Verkettung (Strings kombinieren)}}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`first\_name = 'albert' \{\{nl\}\} last\_name = 'einstein' \{\{nl\}\} full\_name = first\_name + ' ' + last\_name \{\{nl\}\} print(full\_name)` \{\{nl\}\} \textgreater{}\textgreater{} albert einstein} \tn % Row Count 10 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Variablen werden zum Speichern von Zahlenwerten, Zeichen oder Strings verwendet. Ein String ist eine Reihe von Zeichen, die von einfachen oder doppelten Anführungszeichen umgeben sind.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Datentypen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Numerische Typen}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `int, long` \{\{nl\}\} \{\{nl\}\}`float` & für ganze Zahlen (long ist für besonders gro{\ss}e Zahlen) \{\{nl\}\}\{\{nl\}\} für Kommazahlen \tn % Row Count 6 (+ 5) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Boolsche Werte}}} \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} `bool` & Wahrheitswerte (true, false) \tn % Row Count 9 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Arithmetische Operationen}}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} `x+y` \{\{nl\}\} `x-y` \{\{nl\}\} `x*y` \{\{nl\}\} `x/y` \{\{nl\}\} `x\%y` \{\{nl\}\} `x**y` & Addition \{\{nl\}\} Subtraktion \{\{nl\}\} Multiplikation \{\{nl\}\} Division \{\{nl\}\} Rest bei ganzahliger Division \{\{nl\}\} Potenz \tn % Row Count 16 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Schleifen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Eine einfache While-Schleife} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`current\_value = 1\{\{nl\}\} while current\_value \textless{}= 5:\{\{nl\}\} \seqsplit{~~~~print(current\_value)} \{\{nl\}\}~~~~current\_value += 1`} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Den Benutzer entscheiden lassen, wann die Schleife beendet werden soll} \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`msg = ''\{\{nl\}\} while msg != 'quit':\{\{nl\}\} ~~~~msg = input("Wie ist deine Nachricht? ")` \{\{nl\}\} \textless{}\textless{} Hallo Welt!\{\{nl\}\}~~~~~~`print(msg)` \{\{nl\}\} \textgreater{}\textgreater{} Hallo Welt!} \tn % Row Count 12 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Eine while-Schleife wiederholt einen Codeblock, solange wie eine bestimmte Bedingung erfüllt ist.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Tupel}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Tupel erstellen}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`dimensionen = (1920, 1080)`} \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Tupel {\"a}hneln Listen, aber die Elemente in einem Tupel k{\"o}nnen nicht ge{\"a}ndert werden.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Listen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Liste erstellen}} \{\{nl\}\} \textasciicircum{}Strings geh{\"o}ren in einfache Anführungszeichen\textasciicircum{}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`liste = {[}elem0, elem1, elem2{]}`} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{erstes und letztes Element erhalten}}} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`erstesElem = liste{[}0{]} \{\{nl\}\} letztesElem = liste{[}-1{]}`} \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Elemente zu einer Liste hinzufügen}}} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`liste = {[}{]} \{\{nl\}\} liste.append(elem1) \{\{nl\}\} liste.append(elem2) \{\{nl\}\} liste.append(elem3) \{\{nl\}\}`} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Listen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Durchgehen einer Liste}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`for elem in liste: \{\{nl\}\} print(elem)` \{\{nl\}\} je nachdem, was `elem` für einen Typ hat, wird eine Zahl, ein Zeichen oder ein String ausgegeben \{\{nl\}\} \textgreater{}\textgreater{}4 \{\{nl\}\}\textgreater{}\textgreater{}a \{\{nl\}\}\textgreater{}\textgreater{}Hallo \{\{nl\}\}\textgreater{}\textgreater{}3,46} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Numerische Listen erstellen}}} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`quadrate = {[}{]} \{\{nl\}\} for x in range(1, 11): \{\{nl\}\}~ quadrate.append(x**2)`} \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Listen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Abkürzung}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`quadrate = {[}x**2 for x in range(1, 11){]}`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Listen teilen}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`finalisten = {[}'sam', 'bob', 'ada', 'bea'{]} \{\{nl\}\} erstenBeiden = finalisten{[}:2{]}`} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Listen kopieren}}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`kopieVonListe = liste{[}:{]}`} \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Eine Liste speichert eine Reihe von Elementen (Zahlen, Zeichen, Strings, Objekte, ...) in einer bestimmten Reihenfolge. Du greifst auf Elemente über einen Index oder innerhalb einer Schleife zu.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Benutzereingabe}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Aufforderung zur Eingabe}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`name = input("Wie ist dein Name? ") \{\{nl\}\} print("Hallo, " + name + "!")` \{\{nl\}\} \textless{}\textless{} Steve \{\{nl\}\} Wenn auf dem Bildschirm die Frage "Wie ist dein Name? " steht, ist man aufgefordert eine Eingabe zu t{\"a}tigen. Diese wird in der Variablen {\bf{name}} gespeichert. \{\{nl\}\} \textgreater{}\textgreater{} Hallo, Steve!} \tn % Row Count 7 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Benutzereingabe}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Aufforderung zur Zahleneingabe}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`alter = input("Wie alt bist du? ")` \{\{nl\}\} \textless{}\textless{} 16 \{\{nl\}\} `alter = int(alter)` \{\{nl\}\} Hier findet eine Typumformung statt, da jede Eingabe zun{\"a}chst als String gespeichert wird. \{\{nl\}\}\{\{nl\}\} `pi = input("Was ist der Wert von Pi? ")` \{\{nl\}\} \textless{}\textless{} 3,141592654 \{\{nl\}\} `pi = float(pi)`} \tn % Row Count 7 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Deine Programme k{\"o}nnen den Benutzer zur Eingabe auffordern. Alle Eingaben werden als String gespeichert.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Funktionen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Eine einfache Funktion} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`def begruesse\_benutzer():\{\{nl\}\}` Zeigt eine Begrüssung.`\{\{nl\}\}~~~~ print("Hallo!")\{\{nl\}\}\{\{nl\}\} begruesse\_benutzer()` \{\{nl\}\} \textgreater{}\textgreater{} Hallo!} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Argumente übergeben} \tn % Row Count 6 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`def greet\_user(username): \{\{nl\}\}`Zeigt eine persoenliche Begruessung an.`\{\{nl\}\}~~~~ print("Hallo, " + username + " ;D .") \{\{nl\}\}\{\{nl\}\}greet\_user('SummerBYTE')` \{\{nl\}\} \textgreater{}\textgreater{} Hallo, SummerBYTE ;D .} \tn % Row Count 11 (+ 5) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Standardwerte für Parameter} \tn % Row Count 12 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`def \seqsplit{make\_pizza(topping='Bacon'):} \{\{nl\}\}`Erstellt eine einfach belegte Pizza`\{\{nl\}\}~~~~print("Du bekommst eine " + topping + " Pizza.") \{\{nl\}\}\{\{nl\}\}make\_pizza() \{\{nl\}\}make\_pizza('Pepperoni')` \{\{nl\}\} \textgreater{}\textgreater{} Du bekommst eine Bacon Pizza. \{\{nl\}\} \textgreater{}\textgreater{} Du bekommst eine Pepperoni Pizza.} \tn % Row Count 18 (+ 6) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Rückgabe eines Wertes} \tn % Row Count 19 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`def summiere(x, y): \{\{nl\}\}`Gibt die Summe von 2 Zahlen zurück`\{\{nl\}\} ~~~~return x + y \{\{nl\}\}\{\{nl\}\}sum = summiere(3, 5) \{\{nl\}\}print(sum)` \{\{nl\}\} \textgreater{}\textgreater{} 8} \tn % Row Count 23 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{Funktionen sind gekennzeichnete Codebl{\"o}cke, die für eine bestimmte Aufgabe konzipiert sind. Informationen, die an eine Funktion übergeben werden, werden als Argument bezeichnet, und Informationen, die von einer Funktion empfangen werden, werden als Parameter bezeichnet.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{1.7165 cm} x{1.7165 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{Verzweigung}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Vergleichsbedingungen}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} gleich \{\{nl\}\} ungleich \{\{nl\}\} gr{\"o}{\ss}er als \{\{nl\}\}gr{\"o}{\ss}er gleich \{\{nl\}\} kleiner als \{\{nl\}\} kleiner gleich & `x == 42 \{\{nl\}\} x != 42 \{\{nl\}\} x \textgreater{} 42 \{\{nl\}\} x \textgreater{}= 42 \{\{nl\}\} x \textless{} 42 \{\{nl\}\} x \textless{}= 42` \tn % Row Count 7 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Bedingungen mit Listen}}} \tn % Row Count 8 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`elem1 in liste \{\{nl\}\} elem3 not in liste`} \tn % Row Count 9 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Boolesche Werte zuweisen}}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`aktiv = True \{\{nl\}\} pausiert = False`} \tn % Row Count 11 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Einfache if-Verzweigung}}} \tn % Row Count 12 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`if alter \textgreater{}= 18: \{\{nl\}\} print("Du darfst w{\"a}hlen!")` \{\{nl\}\} \textgreater{}\textgreater{} Du darfst w{\"a}hlen!} \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{if-elif-else-Verzweigungen}} \{\{nl\}\} \textasciicircum{}nur ein Codeblock wird ausgeführt (Reihenfolge beachten!)\textasciicircum{}} \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`if alter \textless{} 4: \{\{nl\}\}~ ticketPreis = 0 \{\{nl\}\} elif alter \textless{} 18: \{\{nl\}\}~ ticketPreis = 10 \{\{nl\}\} else: \{\{nl\}\}~ ticketPreis = 15`} \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Verzweigungen werden verwendet, um bestimmte Bedingungen zu testen und entsprechend zu reagieren.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Klassen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Erstellen einer Klasse "Hund"}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`class Dog():\{\{nl\}\}`Stellt einen Hund dar.`\{\{nl\}\} ~~~~def \_\_init\_\_(self, name): \{\{nl\}\}`Initialisiert eine Instanz der Klasse Hund.`\{\{nl\}\} ~~~~~~~~self.name = name\{\{nl\}\}\{\{nl\}\} ~~~~def sit(self): \{\{nl\}\}`Simuliert sitzten.`\{\{nl\}\}~~~~~~~~ print(self.name + " sitzt.") \{\{nl\}\}\{\{nl\}\} my\_dog = Dog('Fluffy') \{\{nl\}\}\{\{nl\}\}print(my\_dog.name + " ist ein braver Junge.")` \{\{nl\}\} \textgreater{}\textgreater{} Fluffy ist ein braver Junge. \{\{nl\}\}`my\_dog.sit()` \{\{nl\}\} \textgreater{}\textgreater{} Fluffy sitzt.} \tn % Row Count 13 (+ 12) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{Klassen}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Vererbung}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`class SARDog(Dog):\{\{nl\}\}`Stelle einen Rettungshund dar.`\{\{nl\}\} \{\{nl\}\} ~~~~ def \_\_init\_\_(self, name):\{\{nl\}\} `Initialisert die Instanz des Rettungshundes.`\{\{nl\}\} ~~~~~~~~ super().\_\_init\_\_(name)\{\{nl\}\}\{\{nl\}\} ~~~~ def search(self):\{\{nl\}\} `Simuliert die Suche.`\{\{nl\}\} \seqsplit{~~~~~~~~ print(self.name} + " sucht.")\{\{nl\}\} \{\{nl\}\} my\_dog = SARDog('Fang')\{\{nl\}\} \{\{nl\}\} print(my\_dog.name + " ist ein Rettungshund.") my\_dog.sit() `\{\{nl\}\} \textgreater{}\textgreater{} Fang ist ein Rettungshund.\{\{nl\}\} `my\_dog.search()` \{\{nl\}\} \textgreater{}\textgreater{} Fang sucht.} \tn % Row Count 14 (+ 13) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{3.833cm}}{\bf\textcolor{white}{W{\"o}rterbücher}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Einfaches W{\"o}rterbuch}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`alien = \{'Farbe': 'grün', 'Punkte': 5\}`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Zugriff auf einen Wert}}} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{\{\{noshy\}\}`print("Die Farbe des Aliens ist " + alien{[}'Farbe'{]})` \{\{nl\}\} \textgreater{}\textgreater{} Die Farbe des Aliens ist grün} \tn % Row Count 6 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{neues Schlüssel-Wert-Paar einfügen}}} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`alien{[}'x\_position'{]} = 0`} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Durchlaufen aller Schlüssel-Wert-Paare}}} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`lieblingszahl = \{'erik': 17, 'julia': 4\} \{\{nl\}\} for name, nummer in lieblingszahl.items(): \{\{nl\}\}~ print(name + ' liebt die ' + str(number))` \{\{nl\}\} \textgreater{}\textgreater{} erik liebt die 17 \{\{nl\}\} \textgreater{}\textgreater{} julia liebt die 4} \tn % Row Count 14 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Durchlaufen aller Schlüssel}}} \tn % Row Count 15 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`lieblingszahl = \{'erik': 17, 'julia': 4\} \{\{nl\}\} for name in lieblingszahl.keys(): \{\{nl\}\}~ print(name + ' liebt eine Zahl')` \{\{nl\}\} \textgreater{}\textgreater{} erik liebt eine Zahl \{\{nl\}\} \textgreater{}\textgreater{} julia liebt eine Zahl} \tn % Row Count 19 (+ 4) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{{\bf{Durchlaufen aller Werte}}} \tn % Row Count 20 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{3.833cm}}{`lieblingszahl = \{'erik': 17, 'julia': 4\} \{\{nl\}\} for nummer in lieblingszahl.values(): \{\{nl\}\} ~print(str(nummer) + ' ist ein Liebling')` \{\{nl\}\} \textgreater{}\textgreater{} 17 ist ein Liebling \{\{nl\}\} \textgreater{}\textgreater{} 4 ist ein Liebling} \tn % Row Count 24 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{3.833cm}}{W{\"o}rterbücher speichern Verbindungen zwischen Informationen. Jedes Element in einem W{\"o}rterbuch ist ein Schlüsselwertpaar.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}