\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{gloo13} \pdfinfo{ /Title (python-methods.pdf) /Creator (Cheatography) /Author (gloo13) /Subject (python methods 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 methods Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{gloo13} via \textcolor{DarkBackground}{\uline{cheatography.com/185324/cs/38728/}}} \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}gloo13 \\ \uline{cheatography.com/gloo13} \\ \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 16th May, 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{0.89586 cm} x{4.08114 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Lists}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{append()} & Adds an element at the end of the list \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{clear()} & Removes all the elements from the list \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} copy() & Returns a copy of the list \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \seqsplit{count()} & Returns the number of elements with the specified value \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{extend()} & Add the elements of a list (or any iterable), to the end of the current list \tn % Row Count 10 (+ 3) % Row 5 \SetRowColor{white} \seqsplit{index()} & Returns the index of the first element with the specified value \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{insert()} & Adds an element at the specified position \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} pop() & Removes the element at the specified position \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{remove()} & Removes the first item with the specified value \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{reverse()} & Reverses the order of the list \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} sort() & Sorts the list \tn % Row Count 21 (+ 1) \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}{String}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{capitalize()} & Converts the first character to upper case \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{casefold()} & Converts string into lower case \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} center() & Returns a centered string \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} count() & Returns the number of times a specified value occurs in a string \tn % Row Count 8 (+ 3) % Row 4 \SetRowColor{LightBackground} encode() & Returns an encoded version of the string \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{endswith()} & Returns true if the string ends with the specified value \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{expandtabs()} & Sets the tab size of the string \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} find() & Searches the string for a specified value and returns the position of where it was found \tn % Row Count 18 (+ 4) % Row 8 \SetRowColor{LightBackground} format() & Formats specified values in a string \tn % Row Count 20 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{format\_map()} & Formats specified values in a string \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} index() & Searches the string for a specified value and returns the position of where it was found \tn % Row Count 26 (+ 4) % Row 11 \SetRowColor{white} isalnum() & Returns True if all characters in the string are alphanumeric \tn % Row Count 29 (+ 3) % Row 12 \SetRowColor{LightBackground} isalpha() & Returns True if all characters in the string are in the alphabet \tn % Row Count 32 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.29402 cm} x{3.68298 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String (cont)}} \tn % Row 13 \SetRowColor{LightBackground} isascii() & Returns True if all characters in the string are ascii characters \tn % Row Count 3 (+ 3) % Row 14 \SetRowColor{white} \seqsplit{isdecimal()} & Returns True if all characters in the string are decimals \tn % Row Count 5 (+ 2) % Row 15 \SetRowColor{LightBackground} isdigit() & Returns True if all characters in the string are digits \tn % Row Count 7 (+ 2) % Row 16 \SetRowColor{white} \seqsplit{isidentifier()} & Returns True if the string is an identifier \tn % Row Count 9 (+ 2) % Row 17 \SetRowColor{LightBackground} islower() & Returns True if all characters in the string are lower case \tn % Row Count 12 (+ 3) % Row 18 \SetRowColor{white} \seqsplit{isnumeric()} & Returns True if all characters in the string are numeric \tn % Row Count 14 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Dictionaries}} \tn % Row 0 \SetRowColor{LightBackground} clear() & Removes all the elements from the dictionary \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} copy() & Returns a copy of the dictionary \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{fromkeys()} & Returns a dictionary with the specified keys and value \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} get() & Returns the value of the specified key \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} items() & Returns a list containing a tuple for each key value pair \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} keys() & Returns a list containing the dictionary's keys \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} pop() & Removes the element with the specified key \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{popitem()} & Removes the last inserted key-value pair \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{setdefault()} & Returns the value of the specified key. If the key does not exist: insert the key, with the specified value \tn % Row Count 20 (+ 4) % Row 9 \SetRowColor{white} update() & Updates the dictionary with the specified key-value pairs \tn % Row Count 22 (+ 2) % Row 10 \SetRowColor{LightBackground} values() & Returns a list of all the values in the dictionary \tn % Row Count 24 (+ 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}{String}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{isprintable()} & Returns True if all characters in the string are printable \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} isspace() & Returns True if all characters in the string are whitespaces \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} istitle() & Returns True if the string follows the rules of a title \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} isupper() & Returns True if all characters in the string are upper case \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} join() & Converts the elements of an iterable into a string \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} ljust() & Returns a left justified version of the string \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} lower() & Converts a string into lower case \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} lstrip() & Returns a left trim version of the string \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{maketrans()} & Returns a translation table to be used in translations \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \seqsplit{partition()} & Returns a tuple where the string is parted into three parts \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} replace() & Returns a string where a specified value is replaced with a specified value \tn % Row Count 23 (+ 3) % Row 11 \SetRowColor{white} rfind() & Searches the string for a specified value and returns the last position of where it was found \tn % Row Count 27 (+ 4) % Row 12 \SetRowColor{LightBackground} rindex() & Searches the string for a specified value and returns the last position of where it was found \tn % Row Count 31 (+ 4) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{1.24425 cm} x{3.73275 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{String (cont)}} \tn % Row 13 \SetRowColor{LightBackground} rjust() & Returns a right justified version of the string \tn % Row Count 2 (+ 2) % Row 14 \SetRowColor{white} rsplit() & Splits the string at the specified separator, and returns a list \tn % Row Count 5 (+ 3) % Row 15 \SetRowColor{LightBackground} rstrip() & Returns a right trim version of the string \tn % Row Count 7 (+ 2) % Row 16 \SetRowColor{white} split() & Splits the string at the specified separator, and returns a list \tn % Row Count 10 (+ 3) % Row 17 \SetRowColor{LightBackground} \seqsplit{splitlines()} & Splits the string at line breaks and returns a list \tn % Row Count 12 (+ 2) % Row 18 \SetRowColor{white} \seqsplit{startswith()} & Returns true if the string starts with the specified value \tn % Row Count 14 (+ 2) % Row 19 \SetRowColor{LightBackground} strip() & Returns a trimmed version of the string \tn % Row Count 16 (+ 2) % Row 20 \SetRowColor{white} \seqsplit{swapcase()} & Swaps cases, lower case becomes upper case and vice versa \tn % Row Count 18 (+ 2) % Row 21 \SetRowColor{LightBackground} title() & Converts the first character of each word to upper case \tn % Row Count 20 (+ 2) % Row 22 \SetRowColor{white} \seqsplit{translate()} & Returns a translated string \tn % Row Count 22 (+ 2) % Row 23 \SetRowColor{LightBackground} upper() & Converts a string into upper case \tn % Row Count 24 (+ 2) % Row 24 \SetRowColor{white} zfill() & Fills the string with a specified number of 0 values at the beginning \tn % Row Count 27 (+ 3) \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}{Tuple}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{count()} & Returns the number of times a specified value occurs in a tuple \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{index()} & Searches the tuple for a specified value and returns the position of where it was found \tn % Row Count 5 (+ 3) \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}{Set}} \tn % Row 0 \SetRowColor{LightBackground} add() & Adds an element to the set \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} clear() & Removes all the elements from the set \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} copy() & Returns a copy of the set \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} difference() & Returns a set containing the difference between two or more sets \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \seqsplit{difference\_update()} & Removes the items in this set that are also included in another, specified set \tn % Row Count 13 (+ 4) % Row 5 \SetRowColor{white} discard() & Remove the specified item \tn % Row Count 15 (+ 2) % Row 6 \SetRowColor{LightBackground} intersection() & Returns a set, that is the intersection of two or more sets \tn % Row Count 18 (+ 3) % Row 7 \SetRowColor{white} \seqsplit{intersection\_update()} & Removes the items in this set that are not present in other, specified set(s) \tn % Row Count 22 (+ 4) % Row 8 \SetRowColor{LightBackground} isdisjoint() & Returns whether two sets have a intersection or not \tn % Row Count 25 (+ 3) % Row 9 \SetRowColor{white} issubset() & Returns whether another set contains this set or not \tn % Row Count 28 (+ 3) % Row 10 \SetRowColor{LightBackground} issuperset() & Returns whether this set contains another set or not \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.09034 cm} x{2.88666 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Set (cont)}} \tn % Row 11 \SetRowColor{LightBackground} pop() & Removes an element from the set \tn % Row Count 2 (+ 2) % Row 12 \SetRowColor{white} remove() & Removes the specified element \tn % Row Count 4 (+ 2) % Row 13 \SetRowColor{LightBackground} \seqsplit{symmetric\_difference()} & Returns a set with the symmetric differences of two sets \tn % Row Count 7 (+ 3) % Row 14 \SetRowColor{white} \seqsplit{symmetric\_difference\_update()} & inserts the symmetric differences from this set and another \tn % Row Count 10 (+ 3) % Row 15 \SetRowColor{LightBackground} union() & Return a set containing the union of sets \tn % Row Count 12 (+ 2) % Row 16 \SetRowColor{white} update() & Update the set with another set, or any other iterable \tn % Row Count 15 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{1.14471 cm} x{3.83229 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{File}} \tn % Row 0 \SetRowColor{LightBackground} close() & Closes the file \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} detach() & Returns the separated raw stream from the buffer \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} fileno() & Returns a number that represents the stream, from the operating system's perspective \tn % Row Count 6 (+ 3) % Row 3 \SetRowColor{white} flush() & Flushes the internal buffer \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} isatty() & Returns whether the file stream is interactive or not \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} read() & Returns the file content \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} \seqsplit{readable()} & Returns whether the file stream can be read or not \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} \seqsplit{readline()} & Returns one line from the file \tn % Row Count 14 (+ 2) % Row 8 \SetRowColor{LightBackground} \seqsplit{readlines()} & Returns a list of lines from the file \tn % Row Count 16 (+ 2) % Row 9 \SetRowColor{white} seek() & Change the file position \tn % Row Count 17 (+ 1) % Row 10 \SetRowColor{LightBackground} \seqsplit{seekable()} & Returns whether the file allows us to change the file position \tn % Row Count 20 (+ 3) % Row 11 \SetRowColor{white} tell() & Returns the current file position \tn % Row Count 22 (+ 2) % Row 12 \SetRowColor{LightBackground} \seqsplit{truncate()} & Resizes the file to a specified size \tn % Row Count 24 (+ 2) % Row 13 \SetRowColor{white} \seqsplit{writable()} & Returns whether the file can be written to or not \tn % Row Count 26 (+ 2) % Row 14 \SetRowColor{LightBackground} write() & Writes the specified string to the file \tn % Row Count 28 (+ 2) % Row 15 \SetRowColor{white} \seqsplit{writelines()} & Writes a list of strings to the file \tn % Row Count 30 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}