\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{Balan275} \pdfinfo{ /Title (my-one.pdf) /Creator (Cheatography) /Author (Balan275) /Subject (My One 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}{9900FF} \definecolor{LightBackground}{HTML}{F8EFFF} \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{My One Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Balan275} via \textcolor{DarkBackground}{\uline{cheatography.com/163857/cs/36262/}}} \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}Balan275 \\ \uline{cheatography.com/balan275} \\ \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 1st January, 2023.\\ 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}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Variable is a container which stores values. But it cannot have reserved Keywords.} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Rules for Variable Names:}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{* It must start with 'letter' or ' \_'} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{* It cannot start with number} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{* It can contain a-z,A-Z,0-9 and \_} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{* Case sensitive. age and AGE different} \tn % Row Count 4 (+ 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}{Keywords}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Python keywords are special reserved words that have specific meanings and purposes and can't be used for anything but those specific purposes. There are 35 Keywords in Python 3.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{We can get List of Keywords by the following command in REPL.} \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} help("keywords")} \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{To get details of each Keyword} \tn % Row Count 8 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} help("pass")} \tn % Row Count 9 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{To get current version available keywords use below commands after import keyword in REPL with snippet \textgreater{}\textgreater{}\textgreater{} import keyword} \tn % Row Count 12 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} keyword.kwlist} \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{[}'False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield'{]}} \tn % Row Count 19 (+ 6) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} len(keyword.kwlist)} \tn % Row Count 20 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{35} \tn % Row Count 21 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} keyword.iskeyword('try')} \tn % Row Count 22 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{True} \tn % Row Count 23 (+ 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}{Lets See All Python Keywords with Usage}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Value Keywords: True, False, None}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = True\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} x is True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = 'True'\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} x is True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} y = False\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} y is False} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = 'False'\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} x is False} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = ''\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} x is True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = "this is a truthy value"\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} x is True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 14 (+ 3) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = "this is a truthy value"\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} bool(x) is True} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} y = "" \# This is falsy\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} y is False} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} y = "" \# This is falsy\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} bool(y) is False} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 22 (+ 3) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = "this is a truthy value" \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} if x is True:~print("x is True") \# Don't do this} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}~} \tn % Row Count 25 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} if x: print("x is truthy") \# Do this\{\{nl\}\}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}x is truthy} \tn % Row Count 27 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} def func(): print("hello")\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} x = func()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}hello} \tn % Row Count 29 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} def func(): print("hello")\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} x = func()\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} print(x)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}None} \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Lets See All Python Keywords with Usage (cont)}} \tn % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{'None' is also the default value returned by a function if it doesn't have a return statement:} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.41887 cm} x{1.64772 cm} x{1.51041 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{5.377cm}}{\bf\textcolor{white}{Operator Keywords: and, or, not, in, is}} \tn % Row 0 \SetRowColor{LightBackground} Math Operator & Other Languages & Python Keyword \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} AND, ∧ & \&\& & and \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} OR, ∨ & || & or \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} NOT, ¬ & ! & not \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} CONTAINS, ∈ & & in \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} IDENTITY & === & is \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}{Examples of and, or, not, in, is..}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x = True\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} y = False} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x and y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x and not y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x or y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} not x or y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x is y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} x is not y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 13 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} not x is y} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 15 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} name = "Chad" \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} "c" in name} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}False} \tn % Row Count 17 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} name = "Chad" \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} "C" in name} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}True} \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Control Flow Keywords: if, elif, else}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{x = ""\{\{nl\}\} y = ""\{\{nl\}\} z = ""\{\{nl\}\} if x: print('x')\{\{nl\}\} elif y: print('y') \{\{nl\}\} else: print('z')} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}z} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{x = ""\{\{nl\}\} y = "Hi"\{\{nl\}\} z = ""\{\{nl\}\} if x: print('x')\{\{nl\}\} elif y: print('y') \{\{nl\}\} else: print('z')} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}y} \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{x = "Hi"\{\{nl\}\} y = ""\{\{nl\}\} z = ""\{\{nl\}\} if x: print('x')\{\{nl\}\} elif y: print('y') \{\{nl\}\} else: print('z')} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}x} \tn % Row Count 12 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Iteration Keywords:}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{for, while, break, continue, else}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{for Loop}}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} for num in range(1, 4):\{\{nl\}\} ~ ~~~~~~~~~~~~print(num)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1\{\{nl\}\}2\{\{nl\}\}3} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\textgreater{}\textgreater{}\textgreater{} people = {[}"Kevin", "Creed", "Jim"{]} \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} for person in people:\{\{nl\}\} ~ ~~~~~~~~~~~~print(f"\{person\} is in Office.")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Kevin is in Office.\{\{nl\}\} Creed is in Office.\{\{nl\}\} Jim is in Office.} \tn % Row Count 11 (+ 6) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{while Loop}}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{}n = 3\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{}while n\textgreater{}0:\{\{nl\}\} ~ ~~~~~~~~~~~~n=-1\{\{nl\}\} ~ ~~~~~~~~~~~~print(n)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}2\{\{nl\}\}1\{\{nl\}\}0} \tn % Row Count 17 (+ 6) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Break Statement}}\{\{nl\}\}nums = {[}1,2,3,4,5,6,7,8,9,10{]}\{\{nl\}\} total\_sum = 0\{\{nl\}\} for num in nums:\{\{nl\}\}~~~~~~total\_sum += num\{\{nl\}\}~~~~~~print(num)\{\{nl\}\}~~~~~~if total\_sum \textgreater{} 10:\{\{nl\}\}~~~~~~~~~~~~break\{\{nl\}\}print("Total Sum:",total\_sum)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1\{\{nl\}\} 2\{\{nl\}\} 3\{\{nl\}\} 4\{\{nl\}\} 5\{\{nl\}\} Total Sum:15} \tn % Row Count 27 (+ 10) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Continue Statement}}\{\{nl\}\}nums = {[}1,2,3,4,5{]}\{\{nl\}\} total\_sum = 0\{\{nl\}\} for num in nums:\{\{nl\}\}~~~~~~total\_sum += num\{\{nl\}\}~~~~~~print(num)\{\{nl\}\}~~~~~~if total\_sum \textgreater{} 3:\{\{nl\}\}~~~~~~~~~~~~continue\{\{nl\}\}~~~~~~print("Check")\{\{nl\}\}print("Total Sum:",total\_sum)} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1\{\{nl\}\} Check\{\{nl\}\} 2\{\{nl\}\} Check\{\{nl\}\} 3\{\{nl\}\} 4\{\{nl\}\} 5\{\{nl\}\} Total Sum: 15} \tn % Row Count 38 (+ 11) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Iteration Keywords: (cont)}} \tn % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{The else Keyword Used With Loops}}} \tn % Row Count 1 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~~~When else keyword used with a loop, the else keyword specifies code that should be run if the loop exits normally, meaning break was not called to exit the loop early.} \tn % Row Count 6 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for i in range(1,5,1):\{\{nl\}\}~~~~~~print(i)\{\{nl\}\} else:\{\{nl\}\}~~~~~~print("Finished")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1\{\{nl\}\} 2\{\{nl\}\} 3\{\{nl\}\} 4\{\{nl\}\} Finished} \tn % Row Count 10 (+ 4) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{for i in range(1,5,1):\{\{nl\}\}~~~~~~print(i)\{\{nl\}\}~~~~~~if i\textgreater{}3:\{\{nl\}\}~~~~~~~~~~~~break\{\{nl\}\} else:\{\{nl\}\}~~~~~~print("Finished")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}1\{\{nl\}\} 2\{\{nl\}\} 3\{\{nl\}\} 4} \tn % Row Count 17 (+ 7) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{for n in range(2, 10):\{\{nl\}\}~~~~~~prime = True\{\{nl\}\}~~~~~~for x in range(2, n):\{\{nl\}\}~~~~~~~~~~~~if n \% x == 0:\{\{nl\}\}~~~~~~~~~~~~~~~~~~prime = False\{\{nl\}\}~~~~~~~~~~~~~~~~~~print(f"\{n\} is not prime")\{\{nl\}\}~~~~~~~~~~~~~~~~~~break\{\{nl\}\}~~~~~~if prime:\{\{nl\}\}~~~~~~~~~~~~print(f"\{n\} is prime!")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}2 is prime!\{\{nl\}\} 3 is prime!\{\{nl\}\} 4 is not prime\{\{nl\}\} 5 is prime!} \tn % Row Count 35 (+ 18) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Iteration Keywords: (cont)}} \tn % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{for n in range(2, 10):\{\{nl\}\}~~~~~~for x in range(2, n):\{\{nl\}\}~~~~~~~~~~~~if n \% x == 0:\{\{nl\}\}~~~~~~~~~~~~~~~~~~print(f"\{n\} is not prime")\{\{nl\}\}~~~~~~~~~~~~~~~~~~break\{\{nl\}\}~~~~~~else:\{\{nl\}\}~~~~~~~~~~~~print(f"\{n\} is prime!")} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}2 is prime!\{\{nl\}\} 3 is prime!\{\{nl\}\} 4 is not prime\{\{nl\}\} 5 is prime!} \tn % Row Count 14 (+ 14) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Structure Keywords:}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{def, class, with, as, pass, lambda}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{The def Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Python's keyword {\bf{def}} is used to define a function or method of a class.} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The basic syntax for defining a function with {\bf{def}} looks like this:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}def \textless{}function\textgreater{}(\textless{}params\textgreater{}):\{\{nl\}\}~~~~~~\textless{}body\textgreater{}} \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Example}}\{\{nl\}\}def func():\{\{nl\}\}~~~~~~print('Hi')\{\{nl\}\}x = func()} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Hi} \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{The class Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Classes are powerful tools in object-oriented programming, To define a class in Python, you use the {\bf{class}} keyword.} \tn % Row Count 15 (+ 4) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The general syntax for defining a class with {\bf{class}} is as follows:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}class MyClass(\textless{}extends\textgreater{}):\{\{nl\}\}~~~~~~\textless{}body\textgreater{}} \tn % Row Count 19 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Example}}} \tn % Row Count 20 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{The with Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Using {\bf{with}} gives you a way to define code to be executed within the context manager's scope. The most basic example of this is when you're working with file I/O in Python.} \tn % Row Count 25 (+ 5) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The general syntax for using {\bf{with}} is as follows:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}with \textless{}context manager\textgreater{} as \textless{}var\textgreater{}:\{\{nl\}\}~~~~~~\textless{}statements\textgreater{}} \tn % Row Count 29 (+ 4) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~~~{\bf{Context managers}} are a really helpful structure in Python. Each {\bf{context manager}} executes specific code before and after the statements you specify. \{\{nl\}\}~~~~~~If you wanted to open a file, do something with that file, and then make sure that the file was closed correctly, then you would use a {\bf{context manager}}. Consider this example in which names.txt contains a list of names, one per line:} \tn % Row Count 39 (+ 10) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Structure Keywords: (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{Example}}\{\{nl\}\}with open("names.txt") as input\_file:\{\{nl\}\}~~~~~~for name in input\_file:\{\{nl\}\}~~~~~~~~~~~~print(name.strip())} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Jim\{\{nl\}\}Pam\{\{nl\}\}Cece} \tn % Row Count 6 (+ 6) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{~~~~~~The file {\bf{I/O context manager}} provided by {\bf{open()}} and initiated with the {\bf{with}} keyword opens the file for reading, assigns the open file pointer to input\_file, then executes whatever code you specify in the with block. Then, after the block is executed, the file pointer closes. Even if your code in the with block raises an exception, the file pointer would still close.} \tn % Row Count 15 (+ 9) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{{\bf{The as Keyword Used With with}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}If you want access to the results of the {\bf{expression}} or {\bf{context manager}} passed to {\bf{with}}, you'll need to alias it using {\bf{as}}. You may have also seen {\bf{as}} used to alias {\bf{imports and exceptions}}, and this is no different. The alias is available in the with block:} \tn % Row Count 22 (+ 7) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The Basic syntax for using {\bf{as}} is given below:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}with \textless{}expr\textgreater{} as \textless{}alias\textgreater{}:\{\{nl\}\}~~~~~~\textless{}statements\textgreater{}} \tn % Row Count 25 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Most of the time, you'll see these two Python keywords, {\bf{with}} and {\bf{as}}, used together} \tn % Row Count 27 (+ 2) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{The pass Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Since Python doesn't have block indicators to specify the end of a block, the {\bf{pass}} keyword is used to specify that the block is intentionally left blank. It's the equivalent of a {\bf{no-op}}, or {\bf{no operation}}.} \tn % Row Count 33 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Structure Keywords: (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Here are a few examples of using pass to specify that the block is blank:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}def my\_function():\{\{nl\}\}~~~~~~pass\{\{nl\}\}\{\{nl\}\}class MyClass:\{\{nl\}\}~~~~~~pass\{\{nl\}\}\{\{nl\}\}if True:\{\{nl\}\}~~~~~~pass} \tn % Row Count 7 (+ 7) % Row 17 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{The lambda Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}The {\bf{lambda}} keyword is used to define a function that doesn't have a name and has only one statement, the results of which are returned. Functions defined with lambda are referred to as {\bf{lambda functions}}:} \tn % Row Count 13 (+ 6) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{The Basic syntax of using {\bf{lambda}} keyword given below:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}lambda \textless{}args\textgreater{}{\bf{:}} \textless{}statement\textgreater{}} \tn % Row Count 16 (+ 3) % Row 19 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{A basic example of a {\bf{lambda function}} that computes the argument raised to the power of 10 would look like this:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}p10 = lambda x: x**3} \tn % Row Count 20 (+ 4) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{This is equivalent to defining a function with def:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}def p10(x){\bf{:}}\{\{nl\}\}~~~~~~return x**3} \tn % Row Count 24 (+ 4) % Row 21 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The above examples return the value {\bf{8}}.} \tn % Row Count 25 (+ 1) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{One common use for a {\bf{lambda}} function is specifying a different behavior for another function. For example, imagine you wanted to sort a list of strings by their integer values. The default behavior of {\bf{sorted()}} would sort the strings alphabetically. But with {\bf{sorted()}}, you can specify which key the list should be sorted on.} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}A lambda function provides a nice way to do so{\bf{:}}:\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} ids = {[}"id1", "id2", "id30", "id3", "id20", "id10"{]}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} sorted(ids)\{\{nl\}\}{[}'id1', 'id10', 'id2', 'id20', 'id3', 'id30'{]}\{\{nl\}\}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} sorted(ids, key=lambda x: int(x{[}2:{]}))\{\{nl\}\}{[}'id1', 'id2', 'id3', 'id10', 'id20', 'id30'{]}} \tn % Row Count 39 (+ 14) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Structure Keywords: (cont)}} \tn % Row 23 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{This example sorts the list based not on alphabetical order but on the numerical order of the last characters of the strings after converting them to integers. Without lambda, you would have had to define a function, give it a name, and then pass it to sorted(). lambda made this code cleaner.} \tn % Row Count 6 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Returning Keywords: return, yield}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{There are two Python keywords used to specify what gets returned from functions or methods: return and yield. Understanding when and where to use return is vital to becoming a better Python programmer. The yield keyword is a more advanced feature of Python, but it can also be a useful tool to understand.} \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{The return Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Python's {\bf{return}} keyword is valid only as part of a function defined with def. When Python encounters this keyword, it will exit the function at that point and return the results of whatever comes after the {\bf{return}} keyword:} \tn % Row Count 13 (+ 6) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Basic Syntax for using {\bf{return}} given below:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}def \textless{}function\textgreater{}(){\bf{:}}\{\{nl\}\}~~~~~~return \textless{}expr\textgreater{}} \tn % Row Count 16 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{When given no expression, {\bf{return}} will return None by default:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\textgreater{}\textgreater{}\textgreater{} def return\_none(){\bf{:}}\{\{nl\}\}~~~~~~~~~~~~~~~return\{\{nl\}\}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} return\_none()\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} r = return\_none()\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} print(r)\{\{nl\}\}None} \tn % Row Count 23 (+ 7) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Most of the time, however, you want to return the results of an expression or a specific value:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\textgreater{}\textgreater{}\textgreater{} def plus\_1(num){\bf{:}}\{\{nl\}\}~~~~~~~~~~~~~~~return num + 1\{\{nl\}\}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} plus\_1(9)\{\{nl\}\}10\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} r = plus\_1(9)\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} print(r)\{\{nl\}\}10} \tn % Row Count 30 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Returning Keywords: return, yield (cont)}} \tn % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{You can even use the return keyword multiple times in a function. This allows you to have multiple exit points in your function. A classic example of when you would want to have multiple return statements is the following recursive solution to calculating factorial:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}def factorial(n){\bf{:}}~~~~~~\{\{nl\}\}~~~~~~if n == 1{\bf{:}}\{\{nl\}\}~~~~~~~~~~~~return 1\{\{nl\}\}~~~~~~else:\{\{nl\}\}~~~~~~~~~~~~return n * factorial(n - 1)} \tn % Row Count 14 (+ 14) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{In the factorial function above, there are two cases in which you would want to return from the function. The first is the base case, when the number is 1, and the second is the regular case, when you want to multiply the current number by the next number's factorial value.} \tn % Row Count 20 (+ 6) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{The yield Keyword}}} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}~~~~~~Python's {\bf{yield}} keyword is kind of like the return keyword in that it specifies what gets returned from a function. However, when a function has a yield statement, what gets returned is a {\bf{generator}}. The generator can then be passed to Python's built-in {\bf{next()}} to get the next value returned from the function. \{\{nl\}\}~~~~~~When you call a function with yield statements, Python executes the function until it reaches the first yield keyword and then returns a generator. These are known as generator functions:} \tn % Row Count 34 (+ 14) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Returning Keywords: return, yield (cont)}} \tn % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Basic Syntax of using {\bf{yield}} statement given below:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}def \textless{}function\textgreater{}(){\bf{:}}\{\{nl\}\}~~~~~~yield \textless{}expr\textgreater{}} \tn % Row Count 4 (+ 4) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The most straightforward example of this would be a generator function that returns the same set of values:} \tn \mymulticolumn{1}{x{5.377cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}\textgreater{}\textgreater{}\textgreater{} def family(){\bf{:}}\{\{nl\}\}~~~~~~~~~~~~~~~~yield "Pam"\{\{nl\}\}~~~~~~~~~~~~~~~~yield "Jim"\{\{nl\}\}~~~~~~~~~~~~~~~~yield "Cece"\{\{nl\}\}~~~~~~~~~~~~~~~~yield "Philip"\{\{nl\}\}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} names = family()\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} names\{\{nl\}\}\textless{}generator object family at 0x7f47a43577d8\textgreater{}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} next(names)\{\{nl\}\}'Pam'\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} next(names)\{\{nl\}\}'Jim'\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} next(names)\{\{nl\}\}'Cece'\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} next(names)\{\{nl\}\}'Philip'\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} next(names)\{\{nl\}\}Traceback (most recent call last):\{\{nl\}\}~~~File "\textless{}stdin\textgreater{}", line 1, in \textless{}module\textgreater{}\{\{nl\}\}StopIteration} \tn % Row Count 25 (+ 21) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Once the {\bf{StopIteration}} exception is raised, the generator is done returning values. In order to go through the names again, you would need to call {\bf{family()}} again and get a new generator. Most of the time, a generator function will be called as part of a {\bf{for}} loop, which does the {\bf{next()}} calls for you.} \tn % Row Count 32 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Test}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Hi \{\{nl\}\}~I \{\{noshy\}\}am} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}