\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{GtM} \pdfinfo{ /Title (imparare-python.pdf) /Creator (Cheatography) /Author (GtM) /Subject (Imparare 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}{2FACEB} \definecolor{LightBackground}{HTML}{F2F9FD} \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{Imparare Python Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{GtM} via \textcolor{DarkBackground}{\uline{cheatography.com/215027/cs/46822/}}} \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}GtM \\ \uline{cheatography.com/gtm} \\ \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 10th August, 2025.\\ 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{tabularx}{17.67cm}{x{7.4261 cm} x{9.8439 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Variabili}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Nomenclatura}} & snake\_case che inizia per \_ o lettera \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Assegnazione\{\{nl\}\}singola}} & `nome\_variabile = valore` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Assegnazione\{\{nl\}\}multipla}} & `var1, var2, var3 = val1, val2, val3`\{\{nl\}\}`var1 = var2 = var3 = valore` \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Sintassi di base}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Commento}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`\# Il tuo commento qui`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{Stampare a schermo}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}`print()`} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{Indentazione}}} \tn \mymulticolumn{1}{x{17.67cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Le righe aventi stessa indentazione appartengono allo stesso blocco di codice.} \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.374 cm} x{10.4594 cm} x{3.0366 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Tipi di dati}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Numerici}} & int, float, complex, bool & \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{Stringhe}} & str \textasciitilde{}(immutabile)\textasciitilde{} & \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Sequenze}} & \{\{nobreak\}\}list \textasciitilde{}(ordinata, mutabile, permette duplicati)\textasciitilde{}\{\{nl\}\}tuple \textasciitilde{}(ordinata, immutabile, permette duplicati)\textasciitilde{}\{\{nl\}\}range & `{[}{]}\{\{nl\}\}()` \tn % Row Count 10 (+ 6) % Row 3 \SetRowColor{white} {\bf{Insiemi}} & set \textasciitilde{}(non ordinato, mutabile, non permette duplicati)\textasciitilde{}\{\{nl\}\}frozenset \textasciitilde{}(non ordinato, immutabile, non permette duplicati)\textasciitilde{} & `\{\}` \tn % Row Count 16 (+ 6) % Row 4 \SetRowColor{LightBackground} {\bf{Dizionari}} & dict \textasciitilde{}(chiave-valore)\textasciitilde{} & \tn % Row Count 18 (+ 2) % Row 5 \SetRowColor{white} {\bf{Binari}} & bytes, bytearray, memoryview & \tn % Row Count 20 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Valore di verità}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{{\bf{{\emph{True}}}}\{\{nl\}\}Un oggetto è considerato vero a meno che la sua classe non definisca un metodo {\emph{\_\_bool\_\_()}} che restituisce False o un metodo {\emph{\_\_len\_\_()}} che restituisce zero.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{{\emph{False}}}}\{\{nl\}\}{\bf{\textgreater{}}} Costanti None e False\{\{nl\}\}{\bf{\textgreater{}}} Zero di qualsiasi tipo numerico (0, 0.0 ecc.)\{\{nl\}\}{\bf{\textgreater{}}} Sequenze o collezioni vuote ("", (), {[}{]} ecc.)} \tn % Row Count 8 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.1931 cm} x{6.2419 cm} x{8.435 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Operatori di confronto}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{\textless{}}} & Strettamente minore & `1 \textless{} 2 \# True` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{\textless{}=}} & Minore o uguale & `1 \textless{}= 1 \# True` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{\textgreater{}}} & Strettamente maggiore & `4 \textgreater{} 2 \# False` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{\textgreater{}=}} & Maggiore o uguale & `3 \textgreater{}= 2 \# True` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{==}} & Uguale & `5 == 7 \# False` \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} {\bf{!=}} & Diverso & `1 != 2 \# True` \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{is}} & Identità dell'oggetto & `a = {[}1,2{]}\{\{nl\}\}b = a\{\{nl\}\}print(a is b) \# True` \tn % Row Count 15 (+ 3) % Row 7 \SetRowColor{white} {\bf{is not}} & Identità dell'oggetto negata & \{\{nobreak\}\}`a = {[}1,2{]}\{\{nl\}\}b = a\{\{nl\}\}print(a is not b) \# False` \tn % Row Count 19 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{\{\{ac\}\}Possono essere concatenati arbitrariamente:\{\{nl\}\}X \textless{} Y \textless{}= Z equivale a X \textless{} Y AND Y \textless{}= Z} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.8923 cm} x{6.4106 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Operatori numerici}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{x + y}} & Addizione & `3 + 4 = 7` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{x - y}} & Sottrazione & `5 – 2 = 3` \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{x * y}} & Prodotto & `7 * 1 = 7` \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{x / y}} & Divisione & `8 / 4 = 2` \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} {\bf{x // y}} & Divisione arrotondata per difetto & `3 // 2 = 1\{\{nl\}\}-1 // 2 = -1` \tn % Row Count 7 (+ 3) % Row 5 \SetRowColor{white} {\bf{x \% y}} & Modulo (ritorna il resto della divisione) & `7 \% 3 = 1` \tn % Row Count 10 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{-x}} & Negazione & `-5` \tn % Row Count 11 (+ 1) % Row 7 \SetRowColor{white} {\bf{abs(x)}} & Valore assoluto & `abs(-5.5) = 5.5` \tn % Row Count 13 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{int(x)}} & Conversione in int & `int("12") = 12\{\{nl\}\}int(7.2) = 7` \tn % Row Count 16 (+ 3) % Row 9 \SetRowColor{white} {\bf{float(x)}} & Conversione in float & `float(7) = 7.0` \tn % Row Count 18 (+ 2) % Row 10 \SetRowColor{LightBackground} {\bf{complex(re, im)}}\{\{nobreak\}\} & Conversione in numero complesso & `complex("3 + 5j")` \tn % Row Count 21 (+ 3) % Row 11 \SetRowColor{white} {\bf{divmod(x, y)}} & Ritorna una tupla contenente quoziente intero e modulo dei parametri & `divmod(5, 2) = (2, 1)` \tn % Row Count 26 (+ 5) % Row 12 \SetRowColor{LightBackground} {\bf{pow(x, y)\{\{nl\}\}x ** y}} & Potenza & `pow(2, 3) = 8\{\{nl\}\}2 ** 3 = 8` \tn % Row Count 29 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{Quando gli operandi sono di tipi numerici differenti, il tipo più piccolo viene convertito in quello più grande (int \textless{} float \textless{} complex).} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.7114 cm} x{6.5793 cm} x{6.5793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Operatori booleani}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{x or y}}\{\{nobreak\}\} & True se almeno uno tra x e y è True, altrimenti False. & Non valuta il secondo argomento se il primo è True. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{x and y}}\{\{nobreak\}\} & True se entrambi x e y sono True, altrimenti False. & Non valuta il secondo argomento se il primo è False. \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{not x}} & True se x è False, altrimenti False. & Ha priorità inferiore rispetto agli operatori non booleani * \tn % Row Count 13 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{* not a == b -\textgreater{} not (a == b)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.7994 cm} x{13.4706 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Tipi Numerici}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{int}} & Numeri interi a precisione illimitata.\{\{nl\}\}Costruttore -\textgreater{} {\emph{int()}} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{float}} & Numeri in virgola mobile, si utilizza il punto tra parte intera e parte decimale.\{\{nl\}\}Costruttore -\textgreater{} {\emph{float()}} \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{complex}} & Numeri complessi, composti da una parte reale (n.real) ed una parte immaginaria (n.imag).\{\{nl\}\}Costruttore -\textgreater{} {\emph{complex()}} \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} {\bf{bool}} & Valori di verità (True e False). \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.5549 cm} x{6.0732 cm} x{6.2419 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Stringhe}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Assegnazione}} & `stringa = "Hello"\{\{nl\}\}stringa = 'Hello'` & \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Stringa multiriga}} & `"""Hello,\{\{nl\}\}it's\{\{nl\}\}me"""` & \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{Accedere ai caratteri}} & `stringa{[}0{]}\{\{nl\}\}stringa{[}-1{]}` & `\# primo carattere\{\{nl\}\}\# ultimo carattere` \tn % Row Count 10 (+ 4) % Row 3 \SetRowColor{white} {\bf{Lunghezza}} & \seqsplit{`len("Hello")`} & `\# 5` \tn % Row Count 12 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Sottostringa}} & `stringa{[}:n{]}\{\{nl\}\}stringa{[}n:{]}\{\{nl\}\}stringa{[}n:m{]}` & `\# da inizio a \_n\{\{nl\}\}\# da °n a fine\{\{nl\}\}\# da °n a \_m` \tn % Row Count 17 (+ 5) % Row 5 \SetRowColor{white} \{\{nobreak\}\}{\bf{Concatenazione}} & `"ab" + "cd"` & `\# "abcd"` \tn % Row Count 20 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{Ripetizione}} & `""Hello"\textbackslash{} * 2` & \seqsplit{`\#"HelloHello"`} \tn % Row Count 22 (+ 2) % Row 7 \SetRowColor{white} {\bf{Formattazione}} & `f"Ho \{10\} mele"` & `\# "Ho 10 mele"` \tn % Row Count 24 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{Caratteri di escape}} & `\textbackslash{}n\{\{nl\}\}\textbackslash{}t\{\{nl\}\}\textbackslash{}' ` & `\# new line\{\{nl\}\}\# tab\{\{nl\}\}\# '` \tn % Row Count 27 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{°x -\textgreater{} incluso / \_x -\textgreater{} escluso} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle stringhe}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{capitalize()}} & \seqsplit{`"heLLo".capitalize()`} & `\# "Hello"` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{casefold()}} & \seqsplit{`"HeLLo".casefold()`} & `\# "hello"` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{center()}} & \seqsplit{`"Hello".center(7},"-")` & `\# "-Hello-"` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{count()}} & \seqsplit{`"Hello".count("l")`} & `\# 2` \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{endswith()}} & `"Hello".endswith("lo")\{\{nl\}\}"Hello".endswith("ab")` & `\# True\{\{nl\}\}\# False` \tn % Row Count 12 (+ 4) % Row 5 \SetRowColor{white} {\bf{expandtabs()}} & `"1\textbackslash{}t2".expandtabs(1)` & `\# "1 2"` \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{find()}} & \seqsplit{`"Hello".find("l")`} & `\# 2` \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} {\bf{format()}} & `"Hel\{\}".format("lo")` & `\# "Hello"` \tn % Row Count 18 (+ 2) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}{\bf{format\_map()}} & come {\emph{format()}} & Accetta dizionari come parametri \tn % Row Count 21 (+ 3) % Row 9 \SetRowColor{white} {\bf{index()}} & come {\emph{find()}} & ValueError se non trova la sottostringa \tn % Row Count 24 (+ 3) % Row 10 \SetRowColor{LightBackground} {\bf{isalnum()}} & `"ABC123".isalnum()\{\{nl\}\}"ab!12\_".isalnum()` & `\# True\{\{nl\}\}\# False` \tn % Row Count 28 (+ 4) % Row 11 \SetRowColor{white} {\bf{isalpha()}} & `"Abc".isalpha()\{\{nl\}\}"123".isalpha()` & `\# True\{\{nl\}\}\# False` \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle stringhe (cont)}} \tn % Row 12 \SetRowColor{LightBackground} {\bf{isascii()}} & `"Abc123".isascii()\{\{nl\}\}"Ab\{\{fa-bolt\}\}23".isascii()` & `\# True\{\{nl\}\}\# False` \tn % Row Count 5 (+ 5) % Row 13 \SetRowColor{white} {\bf{isidentifier()}} & `"hello".isidentifier()\{\{nl\}\}"123ab".isidentifier()` & `\# True\{\{nl\}\}\# False` \tn % Row Count 9 (+ 4) % Row 14 \SetRowColor{LightBackground} {\bf{islower()}} & `"hello1".islower()\{\{nl\}\}"Hello1".islower()` & `\# True\{\{nl\}\}\# False` \tn % Row Count 13 (+ 4) % Row 15 \SetRowColor{white} {\bf{isprintable()}} & `"Abc1!".isprintable()\{nl\}\}"A\textbackslash{}t1!".isprintable()` & `\# True\{\{nl\}\}\# False` \tn % Row Count 17 (+ 4) % Row 16 \SetRowColor{LightBackground} {\bf{isspace()}} & `"\textbackslash{}t\textbackslash{}n ".isspace()\{\{nl\}\}"a \seqsplit{b".isspace()`} & `\# True\{\{nl\}\}\# False` \tn % Row Count 21 (+ 4) % Row 17 \SetRowColor{white} {\bf{join()}} & `"\_".join({[}"a","b"{]})` & `\# "a\_b"` \tn % Row Count 23 (+ 2) % Row 18 \SetRowColor{LightBackground} {\bf{ljust()}} & \seqsplit{`"Abc".ljust(5},"-")` & `\# "Abc-{}-"` \tn % Row Count 25 (+ 2) % Row 19 \SetRowColor{white} {\bf{lower()}} & \seqsplit{`"HELLO".lower()`} & `\# "hello"` \tn % Row Count 27 (+ 2) % Row 20 \SetRowColor{LightBackground} {\bf{lstrip()}} & \seqsplit{`"-Hello-".lstrip("-")`} & `\# "Hello-"` \tn % Row Count 29 (+ 2) % Row 21 \SetRowColor{white} {\bf{maketrans()\{\{nl\}\}translate()}} & `map1 = str.maketrans(\{"a":1,"b":2\})\})\{\{nl\}\}map2 = \seqsplit{str.maketrans("ab"},"12")\{\{nl\}\}map3 = \seqsplit{str.maketrans("ab"},"12","c")\{\{nl\}\}"abc".translate(map1)\{\{nl\}\}"abc".translate(map2)\{\{nl\}\}"abc".translate(map3)` & `\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# "12c"\{\{nl\}\}\# "12c"\{\{nl\}\}\# "12"` \tn % Row Count 45 (+ 16) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle stringhe (cont)}} \tn % Row 22 \SetRowColor{LightBackground} {\bf{partition()}} & \seqsplit{`"a-b-c".partition()`} & `\# ("a","-","b-c")` \tn % Row Count 2 (+ 2) % Row 23 \SetRowColor{white} {\bf{replace()}} & \seqsplit{`"abc".replace("b"},"0")` & `\# "a0c"` \tn % Row Count 4 (+ 2) % Row 24 \SetRowColor{LightBackground} {\bf{rfind()}} & \seqsplit{`"Hello".rfind("l")`} & `\# 3` \tn % Row Count 6 (+ 2) % Row 25 \SetRowColor{white} {\bf{rindex()}} & come {\emph{rfind()}} & ValueError se non trova la sottostringa \tn % Row Count 9 (+ 3) % Row 26 \SetRowColor{LightBackground} {\bf{rjust()}} & \seqsplit{`"Abc".rjust(5},"-")` & `\# "-{}-Abc"` \tn % Row Count 11 (+ 2) % Row 27 \SetRowColor{white} {\bf{rpartition()}} & \seqsplit{`"a-b-c".rpartition()`} & `\# ("a-b","-","c")` \tn % Row Count 13 (+ 2) % Row 28 \SetRowColor{LightBackground} {\bf{rsplit()}} & \seqsplit{`"a-b-c".rsplit("-"},1)` & `\# {[}"a-b","c"{]}` \tn % Row Count 15 (+ 2) % Row 29 \SetRowColor{white} {\bf{rstrip()}} & \seqsplit{`"-Hello-".rstrip("-")`} & `\# "-Hello"` \tn % Row Count 17 (+ 2) % Row 30 \SetRowColor{LightBackground} {\bf{split()}} & \seqsplit{`"a-b-c".split("-"},1)` & `\# {[}"a","b-c"{]}` \tn % Row Count 19 (+ 2) % Row 31 \SetRowColor{white} {\bf{splitlines()}} & `"a\textbackslash{}nb".splitlines()` & `\# {[}"a","b"{]}` \tn % Row Count 21 (+ 2) % Row 32 \SetRowColor{LightBackground} {\bf{startswith()}} & `"abc".startswith("a")\{\{nl\}\}"abc".startswith("c")` & `\# True\{\{nl\}\}\# False` \tn % Row Count 25 (+ 4) % Row 33 \SetRowColor{white} {\bf{strip()}} & \seqsplit{`"-Hello-".strip("-")`} & `\# "Hello"` \tn % Row Count 27 (+ 2) % Row 34 \SetRowColor{LightBackground} {\bf{swapcase()}} & \seqsplit{`"XxX".swapcase()`} & `\# "xXx"` \tn % Row Count 29 (+ 2) % Row 35 \SetRowColor{white} {\bf{title()}} & `"HELLO \seqsplit{world".title()`} & `\# "Hello World"` \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.7358 cm} x{5.5671 cm} x{5.5671 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle stringhe (cont)}} \tn % Row 36 \SetRowColor{LightBackground} {\bf{upper()}} & \seqsplit{`"hello".upper()`} & `\# "HELLO"` \tn % Row Count 2 (+ 2) % Row 37 \SetRowColor{white} {\bf{zfill()}} & `"1".zfill(3)\{\{nl\}\}"-1".zfill(3)` & `\# "001"\{\{nl\}\}\# "-001"` \tn % Row Count 5 (+ 3) % Row 38 \SetRowColor{LightBackground} {\bf{isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()}} & `\# Numeri standard "123"\{\{nl\}\}isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()\{\{nl\}\}\{\{nl\}\}\# Esponenti "\textasciicircum{}123\textasciicircum{}"\{\{nl\}\}isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()\{\{nl\}\}\{\{nl\}\}\# Ideogrammi numerici\{\{nl\}\}isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()\{\{nl\}\}\{\{nl\}\}\# Numeri decimali "12.34"\{\{nl\}\}isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()\{\{nl\}\}\{\{nl\}\}\# Numeri negativi "-123"\{\{nl\}\}isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()\{\{nl\}\}\{\{nl\}\}\# Stringa vuota ""\{\{nl\}\}isdigit()\{\{nl\}\}isnumeric()\{\{nl\}\}isdecimal()` & `\{\{nl\}\}\# True\{\{nl\}\}\# True\{\{nl\}\}\# True\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# True\{\{nl\}\}\# True\{\{nl\}\}\# False\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# False\{\{nl\}\}\# True\{\{nl\}\}\# False\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# False\{\{nl\}\}\# False\{\{nl\}\}\# False\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# False\{\{nl\}\}\# False\{\{nl\}\}\# False\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# False\{\{nl\}\}\# False\{\{nl\}\}\# False` \tn % Row Count 43 (+ 38) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{* più aggressivo rispetto a lower()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.3984 cm} x{5.7358 cm} x{5.7358 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Liste}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Assegnazione}} & `lista = {[}"a", 2, True, {[}1, 2{]}, ...{]}` & \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{Accedere agli elementi}}\{\{nobreak\}\} & `lista{[}0{]}\{\{nl\}\}lista{[}-1{]}` & `\# primo elemento\{\{nl\}\}\# ultimo elemento` \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{Lunghezza}} & `len({[}"a","b"{]})` & `\# 2` \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} {\bf{Concatenazione}} & `{[}1, 2{]} + {[}3, 4{]}` & `\# {[}1, 2, 3, 4{]}` \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{Ripetizione}} & `{[}1, 2{]} * 2` & `\# {[}1, 2, 1, 2{]}` \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} {\bf{Sottolista}} & `lista{[}:n{]}\{\{nl\}\}lista{[}n:{]}\{\{nl\}\}lista{[}n:m{]}` & `\# da inizio a \_n\{\{nl\}\}\# da °n a fine\{\{nl\}\}\# da °n a \_m` \tn % Row Count 18 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{°x -\textgreater{} incluso / \_x -\textgreater{} escluso} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.3618 cm} x{7.2541 cm} x{7.2541 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle liste}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{append()}} & `{[}1, 2{]}.append(3)` & `\# {[}1, 2, 3{]}` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{clear()}} & `{[}1, 2{]}.clear()` & `\# {[}{]}` \tn % Row Count 6 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{copy()}} & `l1 = {[}1, 2{]}\{\{nl\}\}l2 = l1.copy()\{\{nl\}\}l3 = l1` & `\{\{nl\}\}\# l1 e l2 sono due liste distinte\{\{nl\}\}\# l1 e l3 puntano alla stessa lista` \tn % Row Count 11 (+ 5) % Row 3 \SetRowColor{white} {\bf{count()}} & `{[}1, 2, 1{]}.count(1)` & `\# 2` \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{extend()}} & `{[}1, 2{]}.extend({[}"a", "b"{]})` & `\# {[}1, 2, "a", "b"{]}` \tn % Row Count 17 (+ 3) % Row 5 \SetRowColor{white} {\bf{index()}} & `{[}1, 2, 1{]}.index(1)` & `\# 0` \tn % Row Count 20 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{insert()}} & `{[}1, 2{]}.insert(1,3)` & `\# {[}1, 3, 2{]}` \tn % Row Count 23 (+ 3) % Row 7 \SetRowColor{white} {\bf{pop()}} & `{[}1, 2{]}.pop(0)` & `\# {[}2{]} , ritorna 1` \tn % Row Count 25 (+ 2) % Row 8 \SetRowColor{LightBackground} {\bf{remove()}} & `{[}1, 2, 1{]}.remove(1)` & `\# {[}2, 1{]}` \tn % Row Count 28 (+ 3) % Row 9 \SetRowColor{white} {\bf{reverse()}} & `{[}1, 2, 3{]}.reverse()` & `\# {[}3, 2, 1{]}` \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.3618 cm} x{7.2541 cm} x{7.2541 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle liste (cont)}} \tn % Row 10 \SetRowColor{LightBackground} {\bf{sort()}} & `{[}2, 1, 3{]}.sort()\{\{nl\}\}{[}2, 1, 3{]}.sort(reverse=True)` & `\# {[}1, 2, 3{]}\{\{nl\}\}\# {[}3, 2, 1{]}` \tn % Row Count 4 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.2175 cm} x{6.2419 cm} x{6.4106 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Tuple}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Assegnazione}} & `tupla = ("a", 2, True, ...)\{\{nl\}\}stringa = (1, )` & `\{\{nl\}\}\# singolo elemento` \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} {\bf{Accedere agli elementi}} & `tupla{[}0{]}\{\{nl\}\}tupla{[}-1{]}\{\{nl\}\}` & `\# primo elemento\{\{nl\}\}\# ultimo elemento\{\{nl\}\}` \tn % Row Count 8 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{Lunghezza}} & `len((1,2))` & `\# 2` \tn % Row Count 10 (+ 2) % Row 3 \SetRowColor{white} {\bf{Sottotupla}} & `tupla{[}:n{]}\{\{nl\}\}tupla{[}n:{]}\{\{nl\}\}tupla{[}n:m{]}` & `\# da inizio a \_n\{\{nl\}\}\# da °n a fine\{\{nl\}\}\# da °n a \_m` \tn % Row Count 14 (+ 4) % Row 4 \SetRowColor{LightBackground} {\bf{Concatenazione}} & `(1, 2) + (3, 4)` & `\# (1, 2, 3, 4)` \tn % Row Count 16 (+ 2) % Row 5 \SetRowColor{white} {\bf{Ripetizione}} & `(1, 2) * 2` & `\# (1, 2, 1, 2)` \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{°x -\textgreater{} incluso / \_x -\textgreater{} escluso} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{5.2297 cm} x{9.2785 cm} p{2.3618 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Metodi delle tuple}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{count()}} & `(1, 2, 1).count(1)` & `\# 2` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{index()}} & `(1, 2, 3).index(3)` & `\# 2` \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.0244 cm} x{3.5427 cm} x{11.3029 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Range}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{\{\{width=100\}\}{\bf{range(start, stop, step)}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\emph{start}} & \seqsplit{Opzionale} & Numero iniziale (compreso, default = 0) \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} {\emph{stop}} & \seqsplit{Obbligatorio} & Numero finale (escluso) \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} {\emph{step}} & \seqsplit{Opzionale} & Passo dell'incremento (default = 1) \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.0445 cm} x{11.2255 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{IF}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Sintassi}} & `if {\emph{condizione1}}:\{\{nl\}\} {\emph{blocco\_1}}\{\{nl\}\}elif {\emph{condizione2}}:\{\{nl\}\} {\emph{blocco\_2}}\{\{nl\}\}...\{\{nl\}\}else:\{\{nl\}\} {\emph{blocco\_else}}` \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} {\bf{Singola istruzione}} & `if {\emph{condizione}}: {\emph{istruzione}}` \tn % Row Count 7 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Operatore ternario}} & `{\emph{se\_true}} if {\emph{condizione}} else {\emph{se\_false}}` \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} {\bf{pass}}* & `if {\emph{condizione}}:\{\{nl\}\} pass` \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{* i blocchi non possono essere vuoti} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{6.7353 cm} x{10.5347 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{MATCH}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Sintassi}} & `match {\emph{espressione}}:\{\{nl\}\} case {\emph{valore1}}:\{\{nl\}\} {\emph{blocco\_1}}\{\{nl\}\} case {\emph{valore2}}:\{\{nl\}\} {\emph{blocco\_2}}\{\{nl\}\} ...\{\{nl\}\} case \_:\{\{nl\}\} {\emph{blocco\_default}}` \tn % Row Count 8 (+ 8) % Row 1 \SetRowColor{white} {\bf{Combinazione di valori}} & `case {\emph{valore1}} | {\emph{valore2}} | {\emph{...}} :` \tn % Row Count 10 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{Case ... if}} & `match len(stringa):\{\{nl\}\} case 4 if stringa{[}0{]} == "a":\{\{nl\}\} {\emph{blocco\_1}}\{\{nl\}\} ...` \tn % Row Count 14 (+ 4) % Row 3 \SetRowColor{white} {\bf{Case e sequenze}} & `match sequenza:\{\{nl\}\} case {[}x, y{]}:\{\{nl\}\} print(f"Lista con due elementi: \{x\}, \{y\}")\{\{nl\}\} case {[}x, y, z{]}:\{\{nl\}\} print(f"Lista con tre elementi: \{x\}, \{y\}, \{z\}")\{\{nl\}\} case \_: \{\{nl\}\} print("Formato sconosciuto")` \tn % Row Count 25 (+ 11) % Row 4 \SetRowColor{LightBackground} {\bf{Case e dizionari}} & `match dizionario:\{\{nl\}\} case \{"nome": nome, "eta": eta\}:\{\{nl\}\} print(f"Nome: \{nome\}, Età: \{eta\}")\{\{nl\}\} case \{"nome": nome\}:\{\{nl\}\} print(f"Nome: \{nome\}")\{\{nl\}\} case \_:\{\{nl\}\} print("Formato sconosciuto")` \tn % Row Count 35 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.9721 cm} x{13.2979 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{WHILE}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Sintassi}} & `while {\emph{condizione}}:\{\{nl\}\} {\emph{blocco\_codice}}\{\{nl\}\}else:\{\{nl\}\} {\emph{blocco\_else}}` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{break}} & Interrompe il loop \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{continue}} & Salta l'iterazione corrente del loop \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{3.9721 cm} x{13.2979 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{FOR}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Sintassi}} & `for {\emph{elemento}} in {\emph{sequenza}}:\{\{nl\}\} {\emph{blocco\_codice}}\{\{nl\}\}else:\{\{nl\}\} {\emph{blocco\_else}}` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} {\bf{For each}} & `for carattere in stringa:\{\{nl\}\} print(carattere)\{\{nl\}\}else:\{\{nl\}\} print("Ciclo terminato")` \tn % Row Count 7 (+ 4) % Row 2 \SetRowColor{LightBackground} {\bf{Range}} & `for i in range(5):\{\{nl\}\} print(stringa{[}i{]})\{\{nl\}\}else:\{\{nl\}\} print("Ciclo terminato")` \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} {\bf{break}} & Interrompe il loop \tn % Row Count 12 (+ 1) % Row 4 \SetRowColor{LightBackground} {\bf{continue}} & Salta l'iterazione corrente del loop \tn % Row Count 14 (+ 2) % Row 5 \SetRowColor{white} {\bf{pass}}* & `for {\emph{elemento}} in {\emph{sequenza}}:\{\{nl\}\} pass` \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{* i blocchi non possono essere vuoti} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{11.5709 cm} p{5.6991 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Funzioni}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Sintassi}} & `def ` \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.5549 cm} x{6.2419 cm} x{6.0732 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Funzioni}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Sintassi}} & `def {\emph{nome\_funzione}}({\emph{parametri}}):\{\{nl\}\} {\emph{blocco\_codice}}` & return opzionale \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} {\bf{Args (n parametri)}} & `def contaStringhe({\emph{*stringhe}}):\{\{nl\}\} return len(stringhe)\{\{nl\}\}contaStringhe("a")\{\{nl\}\}contaStringhe("a", "b")` & `\{\{nl\}\}\{\{nl\}\}\# 1\{\{nl\}\}\# 2` \tn % Row Count 14 (+ 9) % Row 2 \SetRowColor{LightBackground} {\bf{Keyword}} & `def \seqsplit{ordinaElementi(primo}, secondo):\{\{nl\}\} \seqsplit{print(f"Ordine:} \{primo\} e \{secondo\})\{\{nl\}\}ordinaElementi(1, 2)\{\{nl\}\}ordinaElementi(2, 1)\{\{nl\}\}ordinaElementi(secondo = 2, primo = 1)` & `\{\{nl\}\}\{\{nl\}\}\# "Ordine: 1 e 2"\{\{nl\}\}\# "Ordine: 2 e 1"\{\{nl\}\}\# "Ordine: 1 e 2"` \tn % Row Count 27 (+ 13) % Row 3 \SetRowColor{white} {\bf{Kwargs (n chiave-valore)}} & `def concatenaCV(**kwargs):\{\{nl\}\} concatChiavi = ""\{\{nl\}\} for arg in kwargs:\{\{nl\}\} concatChiavi += arg\{\{nl\}\} concatValori = ""\{\{nl\}\} for val in kwargs.values():\{\{nl\}\} concatValori += val\{\{nl\}\} print(f"\{concatChiavi\} e \{concatValori\}")\{\{nl\}\}concatenaCV(a = 1, b = 2, c = 3)` & `\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\# "abc e 123"` \tn % Row Count 49 (+ 22) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{4.5549 cm} x{6.2419 cm} x{6.0732 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{17.67cm}}{\bf\textcolor{white}{Funzioni (cont)}} \tn % Row 4 \SetRowColor{LightBackground} {\bf{Default}} & `def \seqsplit{stampaNazione(nazione} = "Italia"):\{\{nl\}\} print(nazione)\{\{nl\}\}stampaNazione()\{\{nl\}\}stampaNazione("Germania")` & `\{\{nl\}\}\{\{nl\}\}\# "Italia"\{\{nl\}\}\# "Germania"` \tn % Row Count 9 (+ 9) % Row 5 \SetRowColor{white} {\bf{pass}}* & `def funzione():\{\{nl\}\} pass` & \tn % Row Count 12 (+ 3) % Row 6 \SetRowColor{LightBackground} {\bf{Solo parametri posizionali}} & `def funzione(parametri{\emph{, /}}):\{\{nl\}\} {\emph{blocco\_codice}}` & \tn % Row Count 16 (+ 4) % Row 7 \SetRowColor{white} {\bf{Solo parametri con chiavi}} & `def funzione({\emph{*,}} parametri):\{\{nl\}\} {\emph{blocco\_codice}} ` & \tn % Row Count 21 (+ 5) % Row 8 \SetRowColor{LightBackground} {\bf{Parametri misti}} & `def funzione(pos1, pos2, {\emph{/, *}}, chiave1, chiave2):\{\{nl\}\} {\emph{blocco\_codice}}` & \tn % Row Count 27 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{17.67cm}}{* i blocchi non possono essere vuoti} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \end{document}