\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{davidhemer} \pdfinfo{ /Title (python-basics.pdf) /Creator (Cheatography) /Author (davidhemer) /Subject (Python Basics 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}{414EA3} \definecolor{LightBackground}{HTML}{F3F3F9} \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 Basics Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{davidhemer} via \textcolor{DarkBackground}{\uline{cheatography.com/132946/cs/26989/}}} \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}davidhemer \\ \uline{cheatography.com/davidhemer} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 10th March, 2021.\\ Updated 10th March, 2021.\\ 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{2.356 cm} x{4.18 cm} x{1.064 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Data types}} \tn % Row 0 \SetRowColor{LightBackground} Strings & Represent text & \seqsplit{`"Hello"`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} Integers & Represent whole numbers & `3` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} Floating point numbers & Represent decimal values & \seqsplit{`3.258`} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} Scientific notation & Used to represent very large or very small numbers & \seqsplit{`3.798e17`} \tn % Row Count 9 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.76 cm} x{4.256 cm} x{2.584 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Mathematical operators}} \tn % Row 0 \SetRowColor{LightBackground} + & addition & `3+2` \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} - & subtraction & `72.2-83.7` \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} * & multiplication & `42.8*21.3` \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} / & division & `22.2/3.78` \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} // & integer division & `25//12` \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \% & modulus (remainder) & `35\%2` \tn % Row Count 6 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} x{7.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Comparing numbers}} \tn % Row 0 \SetRowColor{LightBackground} `==` & True if two numbers are equal \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `!=` & True if two numbers are not equal \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `\textless{}=` & True if the first number is less than or equal to the second \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} `\textless{}` & True if the first number is strictly less than the second \tn % Row Count 6 (+ 2) % Row 4 \SetRowColor{LightBackground} `\textgreater{}=` & True if the first number is greater than or equal to the second \tn % Row Count 8 (+ 2) % Row 5 \SetRowColor{white} `\textgreater{}` & True if the first number is strictly greater than the second \tn % Row Count 10 (+ 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}{Importing modules}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import math \newline from sigfig import * \newline from sigfig import round} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The first import statement requires all calls to functions from this module to be prefixed with the module name, e.g. `math.gcd(4,8)` \newline The second import statement allows functions from the sigfig module to be called without prefixes. Name clashes can provide unexpected results. \newline The third import statement allows us to select the module functions that we want to use.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.572 cm} x{1.368 cm} x{2.66 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Math module functions}} \tn % Row 0 \SetRowColor{LightBackground} square root & \seqsplit{math.sqrt} & `math.sqrt\{25.2\}` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} greatest common divisor & \seqsplit{math.gcd} & `math.gcd(25,8)` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} power & \seqsplit{math.pow} & `math.pow(3,5)` \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} pi & \seqsplit{math.pi} & `math.pi` \tn % Row Count 7 (+ 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}{sigfig module}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from sigfig import * \newline \newline \# round to a given number of decimal places \newline round(number, decimals=3) \newline \newline \# round to the given number of significant figures \newline round(number, sigfigs=4)} \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}{Variables}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import math \newline \newline \# assign values to variables \newline r=8.2 \newline c=2*math.pi*r \newline print(c) \newline \newline \# update the value of a variable \newline r=r+5 \newline c=2*math.pi*r \newline print(c)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.812 cm} x{1.444 cm} x{3.344 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Strings}} \tn % Row 0 \SetRowColor{LightBackground} `"Fred"` & \seqsplit{`'Fred'`} & `"The cat sat on the mat"` \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} `'The answer is 3.24'` & \seqsplit{`"\$56.85"`} & `"Beware of the llama!"` \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{`'\#\#\#IMPORTANT\#\#\#'`} & \seqsplit{`"46**2"`} & `"()\$@!\textbackslash{}\#"` \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{Strings are enclosed in double quotes or single quotes.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}---} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{2.08 cm} x{5.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Special characters in strings}} \tn % Row 0 \SetRowColor{LightBackground} `\textbackslash{}n` & New line \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} `\textbackslash{}t` & Horizontal tab \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} `\textbackslash{}\textbackslash{}\textbackslash{}` & Backslash \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} `\textbackslash{}'` & Single quote \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} `\textbackslash{}"` & Double quote \tn % Row Count 5 (+ 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}{Print statements}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{print("Hello World") \newline print("\textbackslash{}"Hello World\textbackslash{}"") \# Enclosed in quotes \newline print("Hello\textbackslash{}nWorld") \# New line between words \newline print("Hello\textbackslash{}tWorld") \# Tab between words} \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}{Formatting strings}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{name="Clarence" \newline print("Hello my name is \{\}".format(name)) \newline \newline pet="cat" \newline place="mat" \newline print("The \{0\} sat on the \{1\}. The \{0\} is very lazy".format(pet, place))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Replacement fields are replaced by the corresponding string from the list of arguments in the format function. \newline The indexes start at 0, so \{0\} is replaced by the value of the first argument.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.76 cm} x{1.368 cm} x{5.472 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Format specifiers}} \tn % Row 0 \SetRowColor{LightBackground} d & `\{0:d\}` & Represents a number as a whole number \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} f & `\{0:.2f\}` & Represents a number with a fixed number of decimal places \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} e & `\{0:.3e\}` & Represents a number using scientific notation. \tn % Row Count 7 (+ 2) % Row 3 \SetRowColor{white} \% & `\{0:.1\%\}` & Represent a decimal as a percentage with the specified number of decimal places \tn % Row Count 10 (+ 3) % Row 4 \SetRowColor{LightBackground} b & `\{0:b\}` & Represent a number in binary form \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{Format specifiers are used in print statements to describe how a number is represented.} \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}{Formatting numbers in strings}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{aNum=3234.374 \newline \newline print("\{0\} with 0 dps is \{0:.0f\}".format(aNum)) \newline print("\{0\} with 1 dp is \{0:.1f\}".format(aNum)) \newline print("\{0\} with 2 dps is \{0:.2f\}".format(aNum)) \newline print("\{0\} in scientific notation is \{0:e\}".format(aNum)) \newline print("\{0\} in scientific notation with one decimal place is \{0:.1e\}".format(aNum)) \newline print("\{0\} in scientific notation with two decimal places is \{0:.2e\}".format(aNum))} \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}{Formatting percentages}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{student1="Beryl" \newline score1=0.828 \newline student2="Marvin" \newline score2=0.738 \newline \newline print("\{0\} got \{1:.0\%\} in her Maths test".format(student1, score1)) \newline print("\{0\} got \{1:.1\%\} in his Maths test".format(student2, score2))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The format specifier `\{0:.2\%\}` formats the first argument in the format list as a percentage with two decimal places. \newline Note that the number being formatted should be represented as a decimal.} \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}{Input statements}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{name=input("Enter your name: ") \newline favFood=input("Enter your favourite food: ") \newline \newline print("Hi \{0\}, seems like your favourite food is \{1\}".format(name, favFood))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Input statements store the resulting value as a string. These strings can then be used in a print statement.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.76 cm} x{4.864 cm} x{1.976 cm} } \SetRowColor{DarkBackground} \mymulticolumn{3}{x{8.4cm}}{\bf\textcolor{white}{Converting strings}} \tn % Row 0 \SetRowColor{LightBackground} int & Converts a string to an integer & \seqsplit{`int("32")`} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} float & Converts a string to a floating point number & \seqsplit{`float("56}.78")` \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}---} \SetRowColor{LightBackground} \mymulticolumn{3}{x{8.4cm}}{String conversions can be used with input statements, where values are always entered as strings.} \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}{Conditional statements}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{age=int(input("How old are you? ")) \newline \newline if (age \textgreater{}= 18): \newline print("Don't forgot to vote.")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Check whether a person is 18 years. Remember to convert the age into an integer before doing the check.} \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}{If then else statement}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import random \newline \newline target=random.randint(1,10) \newline \newline guess=int(input("Enter your guess between 1 and 10: " )) \newline \newline if (guess==target): \newline print("Correct! Well done.") \newline else: \newline print("Wrong. The correct answer was \{:d\}.".format(target)) \newline \newline print("Thanks for playing.")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{A lucky number guessing game. Uses the random module to generate a random number between 1 and 10.} \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}{Else if statements}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import random \newline \newline age=random.randint(1,99) \newline \newline print("Age is \{:d\}.".format(int(age))) \newline if (age \textless{}= 12): \newline print("You are a child, tickets cost \$10.50") \newline elif (age \textless{}60): \newline print("You are an adult, tickets cost \$14.00") \newline else: \newline print("You are a senior, tickets cost \$12.00")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Random number generator used to generate a random age between 1 and 99. \newline Elif branch used to include an additional case. \newline Multiple} \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}{While loops}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import random \newline \newline target=random.randint(1,10) \newline \newline guess=input("Enter your guess between 1 and 10: " ) \newline num\_guesses=1 \newline \newline while (int(guess) != target): \newline print("That was wrong. Try again.") \newline guess=input("Enter your guess between 1 and 10: " ) \newline \seqsplit{num\_guesses=num\_guesses+1} \newline \newline print("Correct! Well done. You took \{0:d\} \seqsplit{guesses.".format(num\_guesses))} \newline print("Thanks for playing.")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The while loop repeats until the condition is no longer true. \newline In this case the while loop repeats while the guess is not correct.} \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}{For loops}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{print("The first ten perfect square numbers are:") \newline \newline for i in range(1,11): \newline print("\{:d\}".format(i**2))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{This loop is repeated 10 times. The values of the loop variable i range from 1 up to, but not including, 11.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}