\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{NotNow} \pdfinfo{ /Title (python-3.pdf) /Creator (Cheatography) /Author (NotNow) /Subject (Python 3 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}{025DA3} \definecolor{LightBackground}{HTML}{EFF4F9} \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 3 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{NotNow} via \textcolor{DarkBackground}{\uline{cheatography.com/108740/cs/21502/}}} \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}NotNow \\ \uline{cheatography.com/notnow} \\ \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 20th January, 2020.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{4.4 cm} x{3.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Types de valeurs}} \tn % Row 0 \SetRowColor{LightBackground} Entier (négatifs aussi) & `18`, `0o22`, `0x12` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Chaîne de charactères & `"Hello World"` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Réel & `3.1415924` \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} Booléen & ` True / False ` \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.204 cm} x{3.04 cm} x{2.356 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Expressions + ordre des priorités}} \tn % Row 0 \SetRowColor{LightBackground} `**` & Exposant & \{\{fa-arrow-left\}\} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`-(unaire)`} & Négatif unaire & \{\{fa-arrow-right\}\} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `* / // \%` & Multiplication, division & \{\{fa-arrow-right\}\} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `+ \seqsplit{-(binaire)`} & Négatif binaire & \{\{fa-arrow-right\}\} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} `\textless{} \textless{}= \textgreater{} \textgreater{}= != ==` & Comparaisons & \{\{fa-arrow-right\}\} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} `not` & NOT logique & \{\{fa-arrow-right\}\} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} `and` & AND logique & \{\{fa-arrow-right\}\} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} `or` & OR logique & \{\{fa-arrow-right\}\} \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Casting}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{`int(whatever)`} & Transforme la variable en un `int` si possible \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`float(whatever)`} & Transforme la variable en un `float` si possible \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`str(whatever)` & Transforme la variable en un `string` si possible \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Alternatives}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{if value \textgreater{} 0 : \newline \#do stuff \newline elif value \textless{} 0 : \newline \#do other shit \newline else : \newline \#do the rest idk} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Boucle while}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{i = 0 \newline while i \textless{}= 4 : \#on répète 5 fois \newline print(i) \newline i += 1} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Faire attention à compter à partir de 0 jusqu'au nombre qu'on a besoin !!} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Break}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.6 cm} x{6.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Procédure vs fonction}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Procédure} & Une suite d'instructions \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Fonction} & Une suite d'instructions avec un retour d'expression \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Fonction}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{def fonction(variable) : \newline \#do stuff \newline return result} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Une procédure n'a tout simplement pas de return. Sinon, c'est la même chose.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Documentation}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Les comentaires peuvent être utilisés lors de la planification, de la description algorithmique et de l'étiquétage d'un code} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Les docstrings décrivent les fonctions d'une fonction} \tn % Row Count 5 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Les commentaires ne peuvent être de plus de 72 charactères} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Typehinting}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{def fonction(var: type) -\textgreater{} type:} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Le type peut être `str, int, float, tuple, list, dict, None` ou `bool`} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Break}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Boucle for}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{lst = {[}"weed",1,2,3,4{]} \newline for l in lst : \newline print(l) \# l = élément de la liste} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{le "for" prend chaque élément dans l'ordre en mémoire. Cela marche aussi pour les paires clé/valeur d'un dictionnaire et pour les éléments d'un tuple} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Types de séquence}} \tn % Row 0 \SetRowColor{LightBackground} Strings & `"Hello World"` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Listes & `{[}3, 7, "weed", (42,69){]}` \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} Tuples & `(3, 7, "weed", {[}42,69{]})` \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \{\{nobreak\}\}Dictionnaires & `\{'Python': 'un language progra', 'le tout': 42, '1': '2'\}` \tn % Row Count 8 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Liste vs Tuple}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}Ressemblances & C'est tous les 2 des collections\{\{noshy\}\} de tous types de données \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} Différences & Les listes sont muables par rapport aux tuples \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{1.04 cm} x{6.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Slicing}} \tn % Row 0 \SetRowColor{LightBackground} Input & `lst = {[}0,1,2,3,4{]}\{\{nl\}\}second\_lst = lst{[}0:5:2{]}` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Output} & `second\_lst = {[}0, 2, 4{]}` \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{1\textasciicircum{}er\textasciicircum{} opérateur : numéro du début de slicing \newline 2\textasciicircum{}ème\textasciicircum{} opérateur : numéro de fin de slicing (!!! la position n'est pas incluse) \newline 3\textasciicircum{}ème\textasciicircum{} opérateur : numéro de pas (la fin inclus mais pas le début) \newline (comme on compte d'habitude)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Opérations sur les séquences}} \tn % Row 0 \SetRowColor{LightBackground} `val {\bf{in}} seq` & Si `val` est dans la séquence `seq` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `val {\bf{not in}} seq` & L'inverse d'au dessus \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} `t = val{[}s:i:j{]}` & Slicing (voir slicing) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} `len(seq)` & Longueur de `seq` \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} `min(seq)` & La valeur minimale de `seq` \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} `max(seq)` & La valeur maximale de `seq` \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`seq.index(val{[}, start{[}, end{]}{]})` & Position de la première valeur `val` avec début et fin non obligatoires \tn % Row Count 15 (+ 4) % Row 7 \SetRowColor{white} `seq.count(val)` & Compte combien de fois on a `val` dans `seq` \tn % Row Count 18 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Opérations sur les strings}} \tn % Row 0 \SetRowColor{LightBackground} `str.lower()` & Renvoie une copie de `str` en minuscule \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `str.upper()` & Renvoie une copie de `str` en majuscule \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`str.replace(old, new)` & Remplace la séquence dans le string `old` par `new` \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} `str.split(delim)` & Divise `str` à l'aide du délimiteur `delim` \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} `str.strip()` & Efface les espaces de `str` \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.76 cm} x{4.24 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Opérations séquences muables (listes)}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}`val{[}s:i:j{]} = t` & Slicing (!! Cela remplace `val`) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `del val{[}s:i:j{]}` & Efface en slicing \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \{\{nobreak\}\}`seq.append(val)` & met `val` à la fin de `seq` \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} `seq.clear()` & Vide `seq` \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} `seq += t` & Étend `seq` avec `t` (si `t` est un string, il prend chaque charactère séparément) \tn % Row Count 11 (+ 5) % Row 5 \SetRowColor{white} `seq` *= `rep` & Répète `seq` et le remet dans la variable \tn % Row Count 14 (+ 3) % Row 6 \SetRowColor{LightBackground} \{\{nobreak\}\}`seq.insert(before,val)` & Insère la valeur après `before` \tn % Row Count 16 (+ 2) % Row 7 \SetRowColor{white} `seq.pop(pos)` & Affiche et efface dans la séquence (on compte à partir de 1 !!) \tn % Row Count 20 (+ 4) % Row 8 \SetRowColor{LightBackground} \{\{nobreak\}\}`seq.remove(val)` & Efface la 1\textasciicircum{}ère\textasciicircum{} valeur dans `seq` \tn % Row Count 22 (+ 2) % Row 9 \SetRowColor{white} `seq.inverse()` & Inverse la séquence \tn % Row Count 23 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Insérer un élement dans une séquence muable}} \tn % Row 0 \SetRowColor{LightBackground} Liste & `list.append{[}truc{]}` ou \{\{nl\}\} `list.insert(pos, truc)` \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \{\{nobreak\}\}Dictionnaire & Refaire un dict avec la position ou `dict{[}"key"{]} = value` pour le mettre en dernière position \tn % Row Count 7 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Operations sur les dictionnaires}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{`dict.items()`} & Retourne les paires clé/valeurs dans une liste de tuples \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{`dict.keys()`} & Retourne les clés dans une liste \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{`dict.values()`} & Retourne les valeurs dans une liste \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Dictionnaire dans un dictionnaire}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{dict{[}key\_1{]}{[}key\_2{]}{[}key\_n{]}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Déballage séquence}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{C'est l'utilisation des tuples comme expression de gauche.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Cela permet de prendre plusieurs variables en même temps ou affecter des variables sans savoir exactement combien il y en a.} \tn % Row Count 5 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Principes de Clean Code}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Préférer l'utilisation des `val` et `not` val dans les alternatives et les boucles} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Utiliser des boucles while quand on a pas besoin de passer par toute la séquence, sinon utiliser une boucle `for`} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Utiliser les fonctions le plus possible (mais sans exagérer non plus)} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Clean Code (À NE PAS FAIRE !!)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{if boolean == True and another\_bool == False : \newline \#do stuff \newline else : \newline \#do something else} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.92 cm} x{4.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Fonctions utiles}} \tn % Row 0 \SetRowColor{LightBackground} \{\{nobreak\}\}`range(start, end, step)` & Génère une séquence de nombres respectant un motif strict. `start` n'est pas obligatoire et non plus le `step`. Le `end` y est \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} `print(whatever)` & Imprime n'importe quoi sur la console (bon pour les debugs) \tn % Row Count 10 (+ 3) % Row 2 \SetRowColor{LightBackground} `type(whatever)` & Nous dit le type de variable \tn % Row Count 12 (+ 2) % Row 3 \SetRowColor{white} `id(whatever)` & Nous montre l'addresse où se situe la valeur de la variable \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} `random()` & Nous donne un nombre au hasard entre `0` et `1` \tn % Row Count 18 (+ 3) % Row 5 \SetRowColor{white} \{\{nobreak\}\}`random.randint(start, end)` & Nous donne un nombre au hasard entre `start` et `end`. `start` et `end` sont obligatoires \tn % Row Count 23 (+ 5) % Row 6 \SetRowColor{LightBackground} `ord('a')` & Transforme un charactère en son code Unicode décimal (`a` = 97) \tn % Row Count 27 (+ 4) % Row 7 \SetRowColor{white} `chr(97)` & Transforme un code Unicode décimal en un charactère Unicode \tn % Row Count 31 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}