\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-data-types.pdf) /Creator (Cheatography) /Author (schmidtlady16) /Subject (Python Data Types 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}{2012A3} \definecolor{LightBackground}{HTML}{F1F0F9} \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 Data Types Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{schmidtlady16} via \textcolor{DarkBackground}{\uline{cheatography.com/208683/cs/44850/}}} \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 30th October, 2024.\\ Updated 30th 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*}{3} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Identificadores}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{Nombres dados a objetos} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} & `mi\_variable, área\_1, \_temp` \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Palabras Clave}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{No pueden usarse como identificadores} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `and` & Operador lógico \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `as` & Crea alias \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{`assert`} & Depura \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} `break` & Sale de un loop \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} `class` & Define una clase \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{`continue`} & Continua la iteración de un loop \tn % Row Count 8 (+ 2) % Row 7 \SetRowColor{white} `def` & Define una función \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} `del` & Elimina un objeto \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} `elif` & Crea una condición \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} `else` & Crea una condición \tn % Row Count 12 (+ 1) % Row 11 \SetRowColor{white} \seqsplit{`except`} & Da lugar a una excepción \tn % Row Count 13 (+ 1) % Row 12 \SetRowColor{LightBackground} `false` & Valor booleano \tn % Row Count 14 (+ 1) % Row 13 \SetRowColor{white} \seqsplit{`finally`} & Siempre se ejecuta, independientemente de si hay una excepción o no \tn % Row Count 17 (+ 3) % Row 14 \SetRowColor{LightBackground} `for` & Crea un loop \tn % Row Count 18 (+ 1) % Row 15 \SetRowColor{white} `from` & Importa cosas especificas de un módulo \tn % Row Count 20 (+ 2) % Row 16 \SetRowColor{LightBackground} \seqsplit{`global`} & Declarar una variable global \tn % Row Count 21 (+ 1) % Row 17 \SetRowColor{white} `if` & Crea una condición \tn % Row Count 22 (+ 1) % Row 18 \SetRowColor{LightBackground} \seqsplit{`import`} & Para importar un módulo \tn % Row Count 23 (+ 1) % Row 19 \SetRowColor{white} `in` & Verifica si un valor específico está dentro de una secuencia \tn % Row Count 25 (+ 2) % Row 20 \SetRowColor{LightBackground} `is` & Prueba si dos variables son iguales \tn % Row Count 27 (+ 2) % Row 21 \SetRowColor{white} \seqsplit{`lambda`} & Crea una función anónima \tn % Row Count 28 (+ 1) % Row 22 \SetRowColor{LightBackground} `none` & Representa un valor null \tn % Row Count 29 (+ 1) % Row 23 \SetRowColor{white} \seqsplit{`nonlocal`} & Declara una variable no local \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{0.9954 cm} x{3.9816 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Palabras Clave (cont)}} \tn % Row 24 \SetRowColor{LightBackground} `not` & Operador Lógico \tn % Row Count 1 (+ 1) % Row 25 \SetRowColor{white} `or` & Operador Lógico \tn % Row Count 2 (+ 1) % Row 26 \SetRowColor{LightBackground} `raise` & Plantea una excepción \tn % Row Count 3 (+ 1) % Row 27 \SetRowColor{white} \seqsplit{`return`} & Sale de una función y retorna un valor \tn % Row Count 5 (+ 2) % Row 28 \SetRowColor{LightBackground} `true` & Valor booleano \tn % Row Count 6 (+ 1) % Row 29 \SetRowColor{white} `try` & Comienza una sentencia \tn % Row Count 7 (+ 1) % Row 30 \SetRowColor{LightBackground} & `try...except` \tn % Row Count 8 (+ 1) % Row 31 \SetRowColor{white} `while` & Comienza un loop \tn % Row Count 9 (+ 1) % Row 32 \SetRowColor{LightBackground} `with` & Simplifica el manejo de excepciones \tn % Row Count 11 (+ 2) % Row 33 \SetRowColor{white} `yield` & Devuelve una lista de valores de un generador \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{4.4793 cm} p{0.4977 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Booleanos}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{True}} & 1 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{False}} & 0 \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{} \tn % Row Count 2 (+ 0) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{`es\_verdad = True `} \tn % Row Count 3 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{`no\_es\_verdad = False`} \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.89126 cm} x{3.08574 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores Númericos}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{x + y}} & Suma \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{x - y}} & Resta \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{x * y}} & Multiplicación \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{x / y}} & División, devuelve un flotante \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{x // y}} & División entera \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} {\bf{x \% y}} & Módulo o resto \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} {\bf{x }} y** & Potencia \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} {\bf{-x}} & Negativo \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} {\bf{+x}} & Positivo \tn % Row Count 10 (+ 1) % Row 9 \SetRowColor{white} {\bf{abs(x)}} & Valor absoluto de x \tn % Row Count 11 (+ 1) % Row 10 \SetRowColor{LightBackground} {\bf{divmod (x , y)}} & Cociente y resto de x entre y \tn % Row Count 13 (+ 2) % Row 11 \SetRowColor{white} {\bf{pow (x , y)}} & Eleva x a la potencia de y \tn % Row Count 15 (+ 2) % Row 12 \SetRowColor{LightBackground} {\bf{pow (x , y , z)}} & Calcula (x ** y) \% z \tn % Row Count 17 (+ 2) % Row 13 \SetRowColor{white} {\bf{round (x, n)}} & Redondea x a n decimales \tn % Row Count 19 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.4931 cm} x{3.4839 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Conversión de Enteros}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{bin (i)}} & Convierte i a binario \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{hex (i)}} & Convierte i a hexadecimal \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{int (x)}} & Convierte x a entero \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{int (s, base)}} & Convierte la cadena s a entero en la base especificada \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{oct (i)}} & Convierte i a octal \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.4931 cm} x{3.4839 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Números Complejos}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{a + bj}} & Define un número complejo (a real, b imaginario) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{z.real}} & Parte real de z \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{z.imag}} & Parte imaginaria de z \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} {\bf{z.conjugate()}} & Cambia el signo de la parte imaginaria \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{complex(x, y)}} & Crea un número complejo a partir de x (real) y y (imaginario) \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.34379 cm} x{3.63321 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Escapes de Strings}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{\textbackslash{}newline}} & Escape \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{ \textbackslash{}\textbackslash{} }} & Barra invertida (\textbackslash{}) \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{\textbackslash{}' }} & Comilla simple (') \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} {\bf{\textbackslash{}"}} & Comilla doble (") \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} {\bf{\textbackslash{}a}} & Campana ASCII \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} {\bf{\textbackslash{}b}} & Retroceso ASCII \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} {\bf{\textbackslash{}f}} & Salto de página ASCII \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} {\bf{\textbackslash{}n}} & Nueva línea ASCII \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} {\bf{\textbackslash{}N\{name\}}} & Carácter Unicode con el nombre dado \tn % Row Count 11 (+ 2) % Row 9 \SetRowColor{white} {\bf{\textbackslash{}ooo}} & Carácter con valor octal ooo \tn % Row Count 12 (+ 1) % Row 10 \SetRowColor{LightBackground} {\bf{\textbackslash{}r}} & Retorno de carro ASCII \tn % Row Count 13 (+ 1) % Row 11 \SetRowColor{white} {\bf{\textbackslash{}t}} & Tabulación ASCII \tn % Row Count 14 (+ 1) % Row 12 \SetRowColor{LightBackground} {\bf{\textbackslash{}uhhhh}} & Carácter Unicode de 16 bits hhhh \tn % Row Count 16 (+ 2) % Row 13 \SetRowColor{white} {\bf{\textbackslash{}Uhhhhhhhh}} & Carácter Unicode de 32 bits hhhhhhhh \tn % Row Count 18 (+ 2) % Row 14 \SetRowColor{LightBackground} {\bf{\textbackslash{}v}} & Tabulación vertical ASCII \tn % Row Count 19 (+ 1) % Row 15 \SetRowColor{white} {\bf{\textbackslash{}xhh}} & Carácter con valor hexadecimal hh \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.69218 cm} x{3.28482 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Slicing y Striding de Strings}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{s{[}i{]}}} & Devuelve el carácter en la posición i \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{s{[}start:end{]}}} & Extrae una subcadena desde start hasta end (excluye end) \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{s{[}start:end:step{]}}} & Extrae caracteres desde start hasta end con un intervalo step \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} {\bf{s{[}:end{]}}} & Extrae desde el inicio hasta end \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{s{[}start:{]}}} & Extrae desde start hasta el final de la cadena \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} {\bf{s{[}::-1{]}}} & Invierte la cadena \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.19448 cm} x{3.78252 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores Bit a Bit}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{i | j}} & OR bit a bit entre i y j \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{i \textasciicircum{} j}} & XOR bit a bit entre i y j \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} {\bf{i \& j}} & AND bit a bit entre i y j \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} {\bf{i \textless{}\textless{} j}} & Desplaza i a la izquierda j bits \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{i \textgreater{}\textgreater{} j}} & Desplaza i a la derecha j bits \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} {\bf{\textasciitilde{}i}} & Invierte los bits de i \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}