\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{vpanton} \pdfinfo{ /Title (python-ekids.pdf) /Creator (Cheatography) /Author (vpanton) /Subject (python eKids 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}{587EA3} \definecolor{LightBackground}{HTML}{F4F6F9} \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 eKids Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{vpanton} via \textcolor{DarkBackground}{\uline{cheatography.com/69808/cs/17684/}}} \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}vpanton \\ \uline{cheatography.com/vpanton} \\ \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 29th October, 2018.\\ 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.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Строки}} \tn % Row 0 \SetRowColor{LightBackground} S.find(str) & Поиск до первого появления \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} S.split(sym) & Разбиение по разделителю \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{str.join(list)} & Сборка строки из списка \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} S.upper() & Верхний регистр \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} S.lower() & Нижний регистр \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} ord(sym) & Символ в его код ASCII \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} chr(num) & Код ASCII в символ \tn % Row Count 14 (+ 2) \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}{Списки ( {[} LIST {]} )}} \tn % Row 0 \SetRowColor{LightBackground} list.append(x) & Добавление x \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} list.extend(L) & Добавление списка L \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} list.insert(i,x) & i-ый элемент x \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} list.remove(x) & Удаление x \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} list.pop({[}i{]}) & Удаление i-го элемента \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} list.count(x) & Количество элементов x \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} list.reverse() & Разворот \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} list.clear() & Очистка \tn % Row Count 16 (+ 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}{Условия}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{if a \textless{} -5: \newline print('Low') \newline elif -5 \textless{}= a \textless{}= 5: \newline print('Mid') \newline else: \newline print('High') \newline \newline A = Y if X else Z} \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}{Code Snippets}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{\bf{Loop Over Sequence}} \newline % Row Count 1 (+ 1) for index, value in enumerate(seq): \newline % Row Count 2 (+ 1) print("\{\} : \{\}".format(index, value)) \newline % Row Count 4 (+ 2) {\bf{Loop Over Dictionary}} \newline % Row Count 5 (+ 1) for key in sorted(dict): \newline % Row Count 6 (+ 1) print(dict{[}key{]}) \newline % Row Count 7 (+ 1) {\bf{Read a File}} \newline % Row Count 8 (+ 1) with open("filename", "r") as f: \newline % Row Count 9 (+ 1) for line in f: \newline % Row Count 10 (+ 1) line = line.rstrip("\textbackslash{}n") \# Strip newline \newline % Row Count 12 (+ 2) print(line)% Row Count 13 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{import RANDOM}} \tn % Row 0 \SetRowColor{LightBackground} randint(a,b) & Случайное int (a\textless{}=n\textless{}=b) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} uniform(a,b) & Случайное float (a\textless{}=n\textless{}= b) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} choise(list) & Случайное из list \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} shuffle(list) & \seqsplit{Перемешивание} list \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} random() & Случайное от 0 до 1 \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} gauss(m,s) & \seqsplit{Распределение} Гаусса \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} normalvariate(m,s) & Нормальное \seqsplit{распределение} \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{3.28482 cm} x{1.69218 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Множества ( \{ SET \} )}} \tn % Row 0 \SetRowColor{LightBackground} A = set() & \seqsplit{Создание} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} A.update(B) & A+B \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{A.intersection\_update(B)} & A∩B \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} A.difference\_update(B) & A\textbackslash{}B \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} A.add(x) & \seqsplit{Добавление} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} A.remove(x) & \seqsplit{Удаление} \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} A.clear() & \seqsplit{Очистка} \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.18988 cm} x{2.78712 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Словари ( DICT \{ Key : "Value" \} )}} \tn % Row 0 \SetRowColor{LightBackground} d=dict(key=val) & Создание \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} d.get(key) & Возврат val по key \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} d.items() & Возврат key и val \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} d.keys() & Список ключей \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} d.values() & Список значений \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} d.pop(key()) & Удаление key \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} d.update({[}d2{]}) & \seqsplit{Объединение} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} d.clear() & Очистка \tn % Row Count 15 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Циклы}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{while условие: \newline блок инструкций \newline \newline i = 1 \newline while i \textless{}= 10: \newline print(i ** 2) \newline i += 1 \newline else: \newline print('Цикл окончен, i =', i) \newline \newline for переменная in \seqsplit{подследовательность:} \newline блок инструкций \newline \newline for i in 1, 2, 3, 'one', 'two', 'three': \newline print(i)} \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}{Функции}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{def {\emph{name}}(arg1, arg2, ...): \newline {\emph{statements}} \newline return {\emph{expr}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.74195 cm} x{3.23505 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{import OS}} \tn % Row 0 \SetRowColor{LightBackground} uname() & Сведения об ОС \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} getlogin() & Имя пользователя \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} chdir(path) & Смена директории \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} getcwd() & Текущая директория \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} path() & Путь \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} listdir(path) & Список файлов \tn % Row Count 10 (+ 2) % Row 6 \SetRowColor{LightBackground} mkdir(path) & Создать директоию \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} remove(path) & Удалить \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} rename(a,b) & \seqsplit{Переименовать} \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} system(cmnd) & Команды ОС \tn % Row Count 18 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.54287 cm} x{3.43413 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Встроенные функции}} \tn % Row 0 \SetRowColor{LightBackground} input(text) & Ввод (+text) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} print() & Вывод \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} min(x) & Минимум \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} max(x) & Максимум \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} range(a,z,d) & \seqsplit{Послдовательность} \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} sum(list) & Сумма элементов \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} abs(x) & Модуль |x| \tn % Row Count 10 (+ 1) % Row 7 \SetRowColor{white} round(x,n) & Округление до n знаков \tn % Row Count 12 (+ 2) % Row 8 \SetRowColor{LightBackground} len(x) & Число объектов \tn % Row Count 13 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.04057 cm} x{2.93643 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Работа с файламми}} \tn % Row 0 \SetRowColor{LightBackground} open(file) & Открыть файл \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} close() & Закрыть файл \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{flush()} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{fileno()} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{isatty()} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{next()} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{read(size)} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{readline(size)} \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{readlines(size)} \tn % Row Count 9 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{seek(offset)} \tn % Row Count 10 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{tell()} \tn % Row Count 11 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{truncate(size)} \tn % Row Count 12 (+ 1) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{write(string)} \tn % Row Count 13 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{5.377cm}}{writelines(list)} \tn % Row Count 14 (+ 1) \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}{Управление циклом}} \tn % Row 0 \SetRowColor{LightBackground} break & немедленный выход \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} continue & следующая итерация \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} range(5) & 0 1 2 3 4 \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} range(3,8) & 3 4 5 6 7 \tn % Row Count 6 (+ 1) % Row 4 \SetRowColor{LightBackground} range(2,12,3) & 2 5 8 11 \tn % Row Count 8 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.23965 cm} x{2.73735 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{import RE}} \tn % Row 0 \SetRowColor{LightBackground} compile(str,flag) & Компиляция str в reg \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} findall(re,str) & Поиск в str по re \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} finditer(re,str) & Поиск в str по re \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} match(re,str) & Совпадения по re \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} split(re,str) & Разбиение str по re \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} groups() & Кортеж совпадений \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} sub(a,b,str) & Замена a на b в str \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.24425 cm} x{3.73275 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{\seqsplit{Дополнительные} модули}} \tn % Row 0 \SetRowColor{LightBackground} datetime & Работа с датой и временем \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} itertools & Набор итераторов \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} pickle & Бинаризация данных \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} zlib & Архивы \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} dbm & Базы данных \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} decimal & Более точный float \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}