\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{schmidtlady16} \pdfinfo{ /Title (python-adriana-flores-bacilio.pdf) /Creator (Cheatography) /Author (schmidtlady16) /Subject (Python Adriana Flores Bacilio 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}{2C64A3} \definecolor{LightBackground}{HTML}{F1F5F9} \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 Adriana Flores Bacilio Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{schmidtlady16} via \textcolor{DarkBackground}{\uline{cheatography.com/208683/cs/44762/}}} \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}schmidtlady16 \\ \uline{cheatography.com/schmidtlady16} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 23rd October, 2024.\\ Updated 23rd October, 2024.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{4} \begin{tabularx}{3.833cm}{x{1.09856 cm} x{2.33444 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#1 Data Types}} \tn % Row 0 \SetRowColor{LightBackground} Int & -973,2103654 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Str & "Hola, esto es un String" \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Acceso a Secuencias & "Esto es un string {[}aquí accedes a un índice{]}" \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} Conversión & int ("45") \#Convierte a entero \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} & str(912) \#Convierte a cadena \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#2 Object References}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{No hay variables en Python como tal sino referencias de objetos} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{x = "blue"} \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{y = "green"} \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{z = x} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{El operador = enlaza una referencia a un objeto, no copia el objeto} \tn % Row Count 7 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.6866 cm} x{2.7464 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#3 Collection Data Types}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Tuplas}} & Son inmutables y se crean con paréntesis o comas \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & ("Denmark", "Finland") \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{Listas}} & Son mutables y se crean con corchetes \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} & {[}1,4,9{]} \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\emph{Ejemplo de acceso y mutación de una lista}}} \tn % Row Count 7 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{x = {[} 'zebra', 49, -879{]}} \tn % Row Count 8 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{x{[}1{]} = "forty nine"} \tn % Row Count 9 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Métodos comunes de listas}}} \tn % Row Count 10 (+ 1) % Row 8 \SetRowColor{LightBackground} {\emph{append}} & Añade un elemento al final \tn % Row Count 11 (+ 1) % Row 9 \SetRowColor{white} {\emph{insert}} & Inserta un índice especifíco \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} {\emph{remove}} & Elimina un elemento \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.51495 cm} x{2.91805 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#4 Logical Operations}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Operador de identidad}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{is}} & Verifica si dos referencias apuntan al mismo objetivo \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} & `a is b` \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\emph{True si a y b son el mismo objeto}}} \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Operadores de comparación}}} \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \textless{} & Menor que \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} & `3 \textless{} 5 ` \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} != & Desigualdad \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} & `5 != 3 ` \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} \textless{}= & Menor o igual que \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} & `5 \textless{}= 5 ` \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} == & Igualdad \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} & `5 == 5 ` \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \textgreater{}= & Mayor o igual que \tn % Row Count 15 (+ 1) % Row 14 \SetRowColor{LightBackground} & `5 \textgreater{}= 5 ` \tn % Row Count 16 (+ 1) % Row 15 \SetRowColor{white} \textgreater{} & Mayor que \tn % Row Count 17 (+ 1) % Row 16 \SetRowColor{LightBackground} & `5 \textgreater{} 3 ` \tn % Row Count 18 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Operador de pertenencia}}} \tn % Row Count 19 (+ 1) % Row 18 \SetRowColor{LightBackground} {\bf{in}} & Verifica si un elemento está en una colección \tn % Row Count 21 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`'J' in 'Jung Chan'`} \tn % Row Count 22 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{\#True} \tn % Row Count 23 (+ 1) % Row 21 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Operadores Lógicos}}} \tn % Row Count 24 (+ 1) % Row 22 \SetRowColor{LightBackground} {\bf{and}} & Devuelve True si ambas condiciones son verdaderas \tn % Row Count 26 (+ 2) % Row 23 \SetRowColor{white} & `(5 \textgreater{} 3) and (8 \textgreater{} 6)` \tn % Row Count 27 (+ 1) % Row 24 \SetRowColor{LightBackground} {\bf{or}} & Devuelve True si al menos una de las condiciones es verdadera \tn % Row Count 29 (+ 2) % Row 25 \SetRowColor{white} & `5 \textgreater{} 3 or 8 \textless{} 6 ` \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{3.833cm}{p{0.51495 cm} x{2.91805 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#4 Logical Operations (cont)}} \tn % Row 26 \SetRowColor{LightBackground} {\bf{not}} & Invierte el valor lógico \tn % Row Count 2 (+ 2) % Row 27 \SetRowColor{white} & `not 5 \textgreater{} 3` \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#5 Control Flow Statements}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{If}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`if lines \textless{} 1000:`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`print("small")`} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`elif lines \textless{} 10000:`} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`print("medium")`} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`else:`} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`print("large")`} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{While}}} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`while True:`} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`item = get\_next\_item()`} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`if not item:`} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`break`} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`process\_item(item)`} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{for...in}}} \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`for country in {[}"Denmark"{]}`:} \tn % Row Count 15 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`print(country)`} \tn % Row Count 16 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} x{3.0897 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#6 Arithmetic Operadors}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Operadores básicos}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} + & 9 + 2 output 11 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} - & 9 - 2 output 7 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} * & 9 * 2 output 18 \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} / & 9 / 2 output 4.5 \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} // & 9 // 2 output 4 \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \% & 9 + 2 output 1 \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Operadores aumentados}}} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{Son una forma de realizar operaciones y asignarlas al mismo tiempo} \tn % Row Count 10 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{+=, -= , *= }}} \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\emph{Ejemplo}}} \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`x = 5`} \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`x += 3 `} \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} & {\emph{Es equivalente a x = x + 3, Resultado: 8}} \tn % Row Count 16 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{x{0.82392 cm} x{2.60908 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#7 Input / Output}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{input}} & Captura datos del usuario \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`name= input("Enter name:")`} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{print}} & Muestra salida en la consola \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`print("Total:", total)`} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{3.833cm}{p{0.3433 cm} p{0.3433 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{3.833cm}}{\bf\textcolor{white}{\#8 Creating and calling functions}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\bf{Función}}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{Bloque reutilizable de código} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{que realiza una tarea específica} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\emph{Ejemplo}}} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`def saludar(nombre):`} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`return "Hola, " + nombre`} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{{\emph{llamada a la función}}} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`mensaje = saludar("Carlos")`} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`print(mensaje)`} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Función sin parámetros}}} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`def despedir():`} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`return "Adiós"`} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`print(despedir())`} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Función con varios parámetros}}} \tn % Row Count 14 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`def sumar(a, b):`} \tn % Row Count 15 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`return a + b`} \tn % Row Count 16 (+ 1) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`resultado = sumar(3, 5) `} \tn % Row Count 17 (+ 1) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{{\bf{Función sin return}}} \tn % Row Count 18 (+ 1) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`def \seqsplit{imprimir\_saludo(nombre):`}} \tn % Row Count 19 (+ 1) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{3.833cm}}{`print("Hola, " + nombre)`} \tn % Row Count 20 (+ 1) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{3.833cm}}{`imprimir\_saludo("Ana")`} \tn % Row Count 21 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}