\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{diegojserrano} \pdfinfo{ /Title (python-variables-y-operadores.pdf) /Creator (Cheatography) /Author (diegojserrano) /Subject (Python - variables y operadores 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}{512EA3} \definecolor{LightBackground}{HTML}{F4F1F9} \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 - variables y operadores Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{diegojserrano} via \textcolor{DarkBackground}{\uline{cheatography.com/71015/cs/18362/}}} \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}diegojserrano \\ \uline{cheatography.com/diegojserrano} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 3rd January, 2019.\\ Updated 3rd January, 2019.\\ 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}{x{1.09494 cm} x{3.88206 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Variables}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{Definición} & Porción de memoria usada para guardar un dato del programa \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{Atomicidad} & Las variables pueden guardar un único dato indivisible \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Nombre & Cada variable posee un nombre o identificador que indica la naturaleza del dato que guarda \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} Tipo & Cada variable puede almacenar datos de algún tipo \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Declaración}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\{bl\}\}Las variables no se declaran en python. Son creadas con la primera asignación. Para asignar un valor a una variable se utiliza el operador de asignación: \newline % Row Count 4 (+ 4) `{\emph{nombre}} = {\emph{valor}}` \newline % Row Count 5 (+ 1) `precio = 300` \newline % Row Count 6 (+ 1) `nombre = "Juan"` \newline % Row Count 7 (+ 1) `hay\_error = False`% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Asignación}} \tn % Row 0 \SetRowColor{LightBackground} A la izquierda & Nombre de la variable a modificar \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} A la derecha & Nuevo valor. Puede ser una constante, otra variable o una expresion \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} Constante & Valor fijo: 100, "Hola", True, 3e-2 \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} Variable & El nombre de otra variable. Ambas quedan con el mismo valor. \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{Expresión} & Operación que utiliza uno o más de los operadores válidos para el tipo de datos. \{\{nl\}\}precio * 1.21\{\{nl\}\}nombre + apellido\{\{nl\}\}bueno and bonito and barato \tn % Row Count 16 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Tipos de datos simples}} \tn % Row 0 \SetRowColor{LightBackground} Enteros & Números enteros de cualquier precisión \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Punto flotante & Números con decimales \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Complejos & Números complejos \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} Cadenas & Texto de cualquier longitud \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} Booleanos & Valores de verdad: True o False \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.88666 cm} x{2.09034 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Literales enteros}} \tn % Row 0 \SetRowColor{LightBackground} Decimal & 52 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Hexadecimal & 0xAF \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Octal & 0o245 \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} Binario & 0b101110 \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{4.03137 cm} p{0.94563 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Literales de punto flotante}} \tn % Row 0 \SetRowColor{LightBackground} Punto decimal & 3.14 \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Notación científica & 1.5e2 \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.4839 cm} x{1.4931 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Literales complejos}} \tn % Row 0 \SetRowColor{LightBackground} Sin componente imaginaria & Es un float \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Solo componente imaginaria & 1j \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Complejo & 3 + 1.3j \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Literales de texto}} \tn % Row 0 \SetRowColor{LightBackground} Texto normal & "Hola mundo" \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Con Unicode & u"Son \textbackslash{}u20B3 36.30" \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} Sin caracteres\{\{nl\}\}de escape & r"Dia y \textbackslash{}noche" \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} Con formato & f"Hola \{nombre\}, como andas" \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} Multiples lineas & """Hoy es viernes\{\{nl\}\}es un dia de sol""" \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.18528 cm} p{1.79172 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Literales booleanos}} \tn % Row 0 \SetRowColor{LightBackground} Verdadero & True \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} Falso & False \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores numéricos}} \tn % Row 0 \SetRowColor{LightBackground} + & Suma \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} - & Diferencia o negación \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} * & Producto \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} / & División con decimales \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \% & Resto \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} // & División entera (piso) \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} ** & Potencia \tn % Row Count 7 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{1.44333 cm} x{3.53367 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores de comparación}} \tn % Row 0 \SetRowColor{LightBackground} == & igual \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} != & distinto \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textgreater{} & mayor \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textgreater{}= & mayor o igual \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textless{} & menor \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textless{}= & menor o igual \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} is & mismo objeto \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} is not & distinto objeto \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.69678 cm} x{4.28022 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores lógicos}} \tn % Row 0 \SetRowColor{LightBackground} and & Y lógico \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} or & O lógico \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} not & negación de verdad \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.4977 cm} x{4.4793 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores a nivel de bits}} \tn % Row 0 \SetRowColor{LightBackground} \& & and \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} | & or \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \textasciitilde{} & not \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \textasciicircum{} & xor \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \textgreater{}\textgreater{} & desplazamiento a la derecha \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \textless{}\textless{} & desplazamiento a la izquierda \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.74655 cm} x{4.23045 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores de asignación}} \tn % Row 0 \SetRowColor{LightBackground} = & asignación \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} += & incremento \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} -= & decremento \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{Estos otros operadores pueden combinarse con asignación: {\emph{ / \% // }}* \& | \textasciicircum{} \textgreater{}\textgreater{} \textless{}\textless{}} \tn % Row Count 5 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{No hay ++ -{}- \{\{fa-frown-o\}\}} \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{p{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Operadores de pertenencia}} \tn % Row 0 \SetRowColor{LightBackground} in & pertenece a la colección \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} not in & no pertenece a la colección \tn % Row Count 2 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}