\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{MrDeniz (papapadzul)} \pdfinfo{ /Title (unit-3-math-functions-string-and-objects.pdf) /Creator (Cheatography) /Author (MrDeniz (papapadzul)) /Subject (Unit 3 - Math Functions, String and Objects 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}{4C31A3} \definecolor{LightBackground}{HTML}{F3F2F9} \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{Unit 3 - Math Functions, String and Objects Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{MrDeniz (papapadzul)} via \textcolor{DarkBackground}{\uline{cheatography.com/68635/cs/17877/}}} \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}MrDeniz (papapadzul) \\ \uline{cheatography.com/papapadzul} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 13th November, 2018.\\ Updated 13th November, 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*}{2} \begin{tabularx}{8.4cm}{x{1.444 cm} x{3.952 cm} x{2.204 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Simple Python Built-In Functions}} \tn % Row 0 \SetRowColor{LightBackground} abs(x) & Returns the absolute value for x & abs(-2) is 2 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} max(x1, x2,...) & Returns the largest among x1, x2,... & max(1, 5, 2) is 5 \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} min(x1, x2,...) & Returns the smalles among x1, x2,... & min(1, 5, 2) is 1 \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} pow(a, b) & Same as a ** b & pow(2, 3) is 8 \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{round(x)} & Returns an integer nearest to x. If x is equally close to two inetegers, the even one is returned & round(5.5) is 6 \tn % Row Count 15 (+ 5) % Row 5 \SetRowColor{white} \seqsplit{round(x}, n) & Returns the float value rounded to n digits after the decimal point & \seqsplit{round(5.466}, 2) is 5.47 \tn % Row Count 19 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Mathematical Functions in Python}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{fabs(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Returns the absolute value for x as a float} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{ceil(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Round up x} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{floor(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Round down x} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{exp(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}exponential function x(e\textasciicircum{}x)} \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{log(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Natural logarithms} \tn % Row Count 10 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{log(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Natural logarithms} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{log(x, base)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Logarithms of x for the specified base} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{sqrt(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Square root of x} \tn % Row Count 16 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{sin(x), cos(x), tan(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}sin, cos, tan of x angle in radians} \tn % Row Count 18 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{asin(x), acos(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Inverse of sin, cos of an angle} \tn % Row Count 20 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{degrees(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}convert radians to degrees} \tn % Row Count 22 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{radians(x)} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}convert degrees to radians} \tn % Row Count 24 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Strings and Characters}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{ASCII Code} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}American Standard Code for Information Interchange. Uses numbers 0 - 127. Can be accessed using alt key} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Unicode Code} \tn \mymulticolumn{1}{x{8.4cm}}{\hspace*{6 px}\rule{2px}{6px}\hspace*{6 px}Unicode consortium, starts with \textbackslash{}u and hexadecimal nmbers} \tn % Row Count 7 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.96 cm} x{3.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Escape Sequences for Special Characters}} \tn % Row 0 \SetRowColor{LightBackground} Character Escape Sequence & Name \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \textbackslash{}b & Backspace \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} \textbackslash{}t & Tab \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} \textbackslash{}n & Linefeed \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \textbackslash{}r & Carriage Return \tn % Row Count 6 (+ 1) % Row 5 \SetRowColor{white} \textbackslash{}\textbackslash{} & Backslash \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} \textbackslash{}' & Single Quote \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} \textbackslash{}" & Double Quote \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Printing without the Newline}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{print("AAA", end = ' ') \newline print("BBB", end = '') \newline print("CCC", end = '{\bf{{\emph{') \newline print("DDD", end = '}}}}') \newline \newline displays \newline AAA BBBCCC{\bf{{\emph{DDD}}}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Invoke the print function with the end argument}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{n = 3 \newline id(n) \newline type(n) \newline \newline s = salalah \newline sl = s.lower() \newline print (s) \newline -{}-{}- \newline su = s.upper() \newline print(s) \newline \newline s = "\textbackslash{}t Salalah \textbackslash{}n" \newline print(s) \newline \newline s = s.strip() \newline print(s)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Convert numbers to a string}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{num1 = str(3.4) \newline print (num1) \newline \newline num2 = str(5) \newline print (num2)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Read strings from the keyboard}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{firstname = input("firstname is: ") \newline secondname =input("second name is: ") \newline name = firstname + secondname \newline print (name) \newline \newline print(firstname + " " + secondname)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{To use the + operator to concatenate strings}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{firstname = " Mohammad" \newline secondname = "Ali" \newline name = firstname + secondname \newline print (name) \newline \newline Firstname + = secondname \newline print(firstname) \newline \newline use " " space} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Format Strings and Numbers}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{a = 3 \newline b = .123 \newline c = a / b \newline print(c) \newline -{}-{}- \newline print (round(c,2)) \newline -{}-{}- \newline \newline print (format(c,"10.2f")) \newline print (format(c,"10.2e")) \newline print (format(c,"10.\%") \newline -{}-{}- \newline (for int only) \newline print(format(a,"b")) \#binary \newline print(format(a,"o")) \#octal \newline print(format(a,"x")) \#hexadecimal} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Format Strings and Numbers cont...}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{print (format(c,"10.2f")) \newline print (format(c,"\textless{}10.2f")) \newline print (format(c,"\textgreater{}10.2f") \newline -{}-{}- \newline \newline print(format(a,"b")) \newline print(format(a,"\textless{}b")) \newline print(format(a,"\textgreater{}b")) \newline -{}-{}- \newline s = "I love Python" \newline print(s) \newline print(format(s,"20s")) \newline print(format(s,"\textless{}20s")) \newline print(format(s,"\textgreater{}20s"))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Draw Various Shapes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import turtle \newline \newline turtle.pensize(n) 1-3 \newline turtle.penup() \newline turtle.goto(x,y) (-200,-50) \newline turtle.pendown() \newline turtle.circle(40, steps = 3) \#triangle \newline \newline turtle.done()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Draw graphics with colors and fonts}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import turtle \newline \newline turtle.pensize(n) \newline turtle.penup() \newline turtle.goto(x,y) \newline turtle.pendown() \newline \newline turtle.begin\_fill() \newline turtle.color("color") \newline \newline turtle.circle(40, steps = 3) \newline turtle.end\_fill() \newline \newline turtle.done()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}