\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{ArielMaka} \pdfinfo{ /Title (tipos-de-datos-en-python-3.pdf) /Creator (Cheatography) /Author (ArielMaka) /Subject (Tipos de Datos en 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}{11799E} \definecolor{LightBackground}{HTML}{F0F6F8} \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{Tipos de Datos en Python 3 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{ArielMaka} via \textcolor{DarkBackground}{\uline{cheatography.com/194929/cs/40740/}}} \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}ArielMaka \\ \uline{cheatography.com/arielmaka} \\ \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 9th October, 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{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Identificadores y palabras clave}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{La primera regla se refiere a los personajes iniciales y de continuación. \{\{nl\}\}El carácter de inicio puede ser cualquier cosa que Unicode \{\{nl\}\}considere una letra, incluido el ASCII.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{letras{\bf{ ("a", "b", …, "z", "A", "B", …, "Z")}}, el guión bajo{\bf{ ("\_")}}} \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{" Los identificadores son mayúsculas y minúscula sensible, por lo que, por ejemplo:} \tn % Row Count 9 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{ TAXRATE, Taxrate, TaxRate, taxRate y taxrate}}\{\{nl\}\} son cinco diferentes identificadores.} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Palabras clave de Python} \tn % Row Count 12 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{{\bf{and continue except global lambda pass while as def False if None raise with assert del finally import nonlocal return yield break elif for in not True class else from is or try}}} \tn % Row Count 16 (+ 4) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{¿Podemos decir si un identificador cae en una de estas categorías? \{\{nl\}\}Python tiene un Función incorporada llamada {\bf{dir()}} que devuelve una lista de los atributosde un objeto. \{\{nl\}\}Si esto es llamado sin argumentos, \{\{nl\}\}devuelve la lista de atributos integrados de Python. \{\{nl\}\}Para ejemplo:} \tn % Row Count 23 (+ 7) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{} dir(\_\_builtins\_\_) {[}'ArithmeticError', 'AssertionError',\{\{nl\}\} 'AttributeError', ... 'sum', 'super', 'tuple', 'type', 'vars', 'zip'{]}`} \tn % Row Count 26 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Un solo guión bajo puede usarse como identificador,\{\{nl\}\} y dentro de un intérprete interactivo o Python Shell\{\{nl\}\} Por ejemplo:} \tn % Row Count 29 (+ 3) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{}for \_ in (0, 1, 2, 3, 4, 5): print("Hello")`} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Identificadores y palabras clave (cont)}} \tn % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Módulo Matemático Ejemplo:} \tn % Row Count 1 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{}π = math.pi\{\{nl\}\} ε = 0.0000001\{\{nl\}\} nueva\_área = π {\emph{ radio }} radio \{\{nl\}\}if abs(nueva\_área - vieja\_área) \textless{} ε: \{\{nl\}\}print("las áreas han convergido")`} \tn % Row Count 5 (+ 4) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Ventana Python Shell de IDLE ejemplo:} \tn % Row Count 6 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{} stretch-factor = 1 SyntaxError: can't assign to operator (...) \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} 2miles = 2 SyntaxError: invalid syntax (...) \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} str = 3 \# Legal but BAD\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} l'impôt31 = 4 SyntaxError: EOL while scanning single-quoted string (...)\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} l\_impôt31 = 5 \textgreater{}\textgreater{}\textgreater{}`} \tn % Row Count 12 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Un identificador de Python válido es una secuencia no vacía de caracteres de cualquier longitud. \newline que consta de un "carácter de inicio" y cero o más "caracteres de continuación". \newline Un identificador de este tipo debe obedecer un par de reglas y seguir ciertas convenciones.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Strings}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Las cadenas están representadas por el tipo de datos str inmutable que contiene una secuencia de caracteres Unicode.. La función {\bf{str()}} también se puede usar como función de conversión.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Ejemplos:} \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{a = "Las 'comillas' simples están bien; se debe utilizar el carácter de escape \textbackslash{}"dobles\textbackslash{}".". \{\{nl\}\}b = 'Las \textbackslash{}'comillas\textbackslash{}' simples deben tener carácter de escape; Los "dobles" están bien.'} \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Comparando cadenas} \tn % Row Count 10 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Las cadenas admiten los operadores de comparación habituales \textless{}, \textless{}=, ==, !=, \textgreater{} y \textgreater{}=. Estos Los operadores comparan cadenas byte a byte en la memoria. Por ejemplo, el punto de carácter 0x00C5) se puede representar en bytes codificados en UTF8 en tres diferentes formas: {[}0xE2, 0x84, 0xAB{]}, {[}0xC3, 0x85{]} y {[}0x41, 0xCC, 0x8A{]}.} \tn % Row Count 17 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Tipos integrales}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Python proporciona dos tipos integrales integrados, int y bool.} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{El tamaño de un número entero está limitado\{\{nl\}\} únicamente por la memoria de la máquina.\{\{nl\}\} Hay dos objetos booleanos integrados: \{\{nl\}\}Verdadero y Falso.} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Enteros Ejemplo:} \tn % Row Count 7 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{} 14600926 \# decimal\{\{nl\}\} 14600926\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} \seqsplit{0b110111101100101011011110} \# binary \{\{nl\}\}14600926\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} 0o67545336 \# octal \{\{nl\}\}14600926 \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} 0xDECADE \# hexadecimal \{\{nl\}\}14600926\{\{nl\}\} `} \tn % Row Count 11 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Booleanos Ejemplo:} \tn % Row Count 12 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{} t = True\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} f = False\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} t and f False \{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} t and True True`} \tn % Row Count 14 (+ 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}{Tipos de punto flotante}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{Python proporciona tres tipos de valores de punto flotante: \{\{nl\}\}{\bf{ Los tipos flotantes}} \{\{nl\}\} {\bf{Complejos integrados }}\{\{nl\}\} {\bf{El tipo decimal}}\{\{nl\}\}Decimal de la biblioteca estándar.\{\{nl\}\}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Números de punto flotante Ejemplo:} \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`def equal\_float(a, b): \{\{nl\}\} return abs(a - b) \textless{}= sys.float\_info.epsilon \{\{nl\}\}\{\{nl\}\}\{\{nl\}\} \{\{nl\}\}s = 14.25.hex() \# str s == '0x1.c800000000000p+3' \{\{nl\}\}f = float.fromhex(s) \# float f == 14.25 \{\{nl\}\} t = f.hex() \# str t == '0x1.c800000000000p+3'`} \tn % Row Count 10 (+ 5) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Números complejos Ejemplo:} \tn % Row Count 11 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{} z = -89.5+2.125j\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} z.real, z.imag (-89.5, 2.125)\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} z.conjugate() (-89.5-2.125j)\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} 3-4j.conjugate() (3+4j)`} \tn % Row Count 14 (+ 3) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Numeros decimales Ejemplo:} \tn % Row Count 15 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{`\textgreater{}\textgreater{}\textgreater{} import decimal\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} a = decimal.Decimal(9876)\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} b = decimal.Decimal("54321.012345678987654321")\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} a + b \{\{nl\}\}Decimal('64197.012345678987654321')\{\{nl\}\}\{\{nl\}\}\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} 23 / 1.05 \{\{nl\}\}21.904761904761905\{\{nl\}\} \textgreater{}\textgreater{}\textgreater{} print(23 / 1.05) \{\{nl\}\}21.9047619048\{\{nl\}\}\textgreater{}\textgreater{}\textgreater{} \seqsplit{print(decimal.Decimal(23)} / decimal.Decimal("1.05"))\{\{nl\}\} \seqsplit{21.90476190476190476190476190 `}} \tn % Row Count 23 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \end{document}