\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{jahero} \pdfinfo{ /Title (python-essentials.pdf) /Creator (Cheatography) /Author (jahero) /Subject (python essentials 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}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \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 essentials Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{jahero} via \textcolor{DarkBackground}{\uline{cheatography.com/173037/cs/36353/}}} \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}jahero \\ \uline{cheatography.com/jahero} \\ \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 4th January, 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{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{co budete potřebovat}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Základ}} \newline % Row Count 1 (+ 1) \{\{popup="https://www.python.org/downloads/"\}\}python\{\{/link\}\} - samotný interpretr \newline % Row Count 3 (+ 2) \{\{popup="https://docs.python.org/3/"\}\}docs\{\{/link\}\} \newline % Row Count 5 (+ 2) \{\{popup="https://www.jetbrains.com/pycharm/"\}\}pycharm\{\{/link\}\} - IDE \newline % Row Count 7 (+ 2) \{\{popup="https://pypi.org/"\}\}pypi\{\{/link\}\} - veřejně dostupné knihovny \newline % Row Count 9 (+ 2) {\bf{Nástroje pro vývojáře}} \newline % Row Count 10 (+ 1) \{\{popup="https://pypi.org/project/black/"\}\}black\{\{/link\}\} - formátování kódu \newline % Row Count 12 (+ 2) \{\{popup=""https://pypi.org/project/flake8/"\}\}flake8\{\{/link\}\} - linter \newline % Row Count 14 (+ 2) {\bf{Další}} \newline % Row Count 15 (+ 1) \{\{popup="https://pypi.org/project/jupyter/"\}\}jupyter\{\{/link\}\} - REPL na webu \newline % Row Count 17 (+ 2) \{\{popup="https://pypi.org/project/ipython/"\}\}ipython\{\{/link\}\} - REPL v konzoli% Row Count 19 (+ 2) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{looking around}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{help("if") \newline dir("pathlib")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{základní datové typy}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Skalární}} \newline % Row Count 1 (+ 1) - {\bf{bool}} = `True` / `False` \newline % Row Count 2 (+ 1) - {\bf{int}} = `10`, {\bf{float}} = `10.01` \newline % Row Count 3 (+ 1) - {\bf{str}} = `"nějaký text"` / `'také string'` / `"""multiline string"""` \newline % Row Count 5 (+ 2) {\bf{Kontejnery}} \newline % Row Count 6 (+ 1) - {\bf{list}} = `{[} 1, "apple", some\_var {]}` \newline % Row Count 7 (+ 1) - {\bf{dict}} = `\{ "key" : "val", 10: 20 \}`% Row Count 8 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{aritmetika a základní operátory}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{a, b = 2, 3 \newline x = (a + b) {\emph{ ( 10 / 2 ) \newline x == 25 \# True \newline x != 25 \# False \newline x \textgreater{} 25 \# False \newline \newline a\_na\_druhou = a }}* 2 \# druhá mocnina \newline b\_modulo\_2 = b \% 2 \# zbytek celočíselného dělení} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{identity check vs ekvivalence}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{x = {[} 1, 2 {]} \newline y = {[}1, 2 {]} \newline \newline x == y \# True - stejný obsah \newline x is y \# False - není to stejný objekt} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Operátor `is` porovnává dva objekty na shodu identity (jde o stejný objekt); operátor `==` porovnává dva objekty na shodu obsahu. \newline \newline Singletony - jako je `None` - by se měly porovávat pomocí `is`.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{co je a co není pravda}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{True and False \# False \newline True or False \# True \newline not (True) \# False \newline \newline \# short circuit \newline True or (1 / 0) \# True; short circuit nespustí druhý statement \newline True and (1 / 0) \# ZeroDivisionError: division by zero} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{None (nedefinovaná hodnota)}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{x = None \# proměnná x má nedefinovanou hodnotu \newline \newline x is None \# True \newline x is not None \# False} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{Pozor: porovnání x == None je "antipattern", nepoužívat.} \tn \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}{list a jeho indexace}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{list = {[}{]}}} & definuje prázdný list \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{list{[}0{]}}} = 1 & první položka listu již není 10, ale 1 \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{list{[}-1{]}}} & vrací první položku od konce \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{list{[}i:{]}}} & vrací řez listem od pozice i do konce \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} {\bf{del list{[}i{]}}} & smaže položku na pozici i \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.33919 cm} x{2.63781 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{list a jeho metody}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{list.append(x)}} & přidá na konec x \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\bf{list.extend({[}1,2{]})}} & zploští {[}1,2{]} a obě položky přidá na konec \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} {\bf{list.insert(i,x)}} & přidá na pozici i položku x \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{list.pop(i)}} & odstraní položku na pozici i a vrátí ji \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{list.clear()}}, {\bf{list.copy()}} & reset nebo copy \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} {\bf{list.sort()}}, {\bf{list.reverse()}} & seřadí list ({\bf{in place!}}) \tn % Row Count 13 (+ 2) \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}{dict - indexace}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{dict = \{\}}} & vytvoř prázdný dict \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{dict{[}k{]} = v}} & hodnotu v ulož do slovníku na klíč k \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{dict{[}k{]}}} & vrať hodnotu z klíče k, nebo padni (KeyError) \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} {\bf{del dict{[}k{]}}} & odstraň ze slovníku hodnontu na klíči k \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.14011 cm} x{2.83689 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{dict - metody}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{dict.keys(); dict.values()}} & vrať klíče nebo hodnoty jako iterátor \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} {\bf{dict.items()}} & vrať iterátor tuple (k, v) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{dict.get(k), dict.pop(k)}} & vrať hodnotu z klíče nebo None; vrať a odstraň hodnotu z klíče (rasies) \tn % Row Count 8 (+ 4) % Row 3 \SetRowColor{white} {\bf{dict.update(another\_dict)}} & aktualizuj z jiného slovníku (add or overwrite) \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{dict.clear(). dict.copy()}} & reset, kopie \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}