\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{Rajargs} \pdfinfo{ /Title (python-advanced.pdf) /Creator (Cheatography) /Author (Rajargs) /Subject (Python Advanced 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}{31A30F} \definecolor{LightBackground}{HTML}{F2F9F0} \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 Advanced Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Rajargs} via \textcolor{DarkBackground}{\uline{cheatography.com/177698/cs/37148/}}} \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}Rajargs \\ \uline{cheatography.com/rajargs} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 17th February, 2023.\\ Updated 17th February, 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}{Object}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Every real-world entity is an object.An object has Behaviour (things it does or performs) and Attributes (things that describe it). \newline % Row Count 3 (+ 3) For eg: A Chair object can have behaviour like Movement, Height Adjustment \& Attributes like Color, Make \& Model, and Price.% Row Count 6 (+ 3) } \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}{Encapsulation}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{It means wrapping data into a single unit \& securing it. \newline % Row Count 2 (+ 2) For eg: Drug Capsule wraps different medicines into a single unit and protects them from the outside environment. \newline % Row Count 5 (+ 3) Bank Locker wraps your valuables into a single unit(locker) and protects it via passcode.% Row Count 7 (+ 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}{Abstract class/Method}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Abstract class is a class that cannot be instantiated. However, you can create classes that inherit from an abstract class. An abstract method is an method without an implementation. An abstract class may or may not include abstract methods. \newline % Row Count 5 (+ 5) \{\{nl\}\}Python doesn't directly support abstract classes. But it does offer a module that allows you to define abstract classes.To define an abstract class, you use the abc (abstract base class) module. \newline % Row Count 10 (+ 5) \{\{nl\}\}Ex: \newline % Row Count 11 (+ 1) from abc import ABC, abstractmethod \newline % Row Count 12 (+ 1) class Polygon(ABC): \newline % Row Count 13 (+ 1) @abstractmethod \newline % Row Count 14 (+ 1) def noofsides(self): \newline % Row Count 15 (+ 1) pass% Row Count 16 (+ 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}{Class}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The collection of all related objects is called a class.Consider class as a general category which contains all the related objects inside it. \newline % Row Count 3 (+ 3) For eg: Objects like Wheelchair, Office Chair and Wooden Chair can be a part of the "Chair" class.% Row Count 5 (+ 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}{Abstraction}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Hiding complexity from the user and showing only the relative stuff. \newline % Row Count 2 (+ 2) For Eg: In Car, all the complexity like the engine, machinery, etc is hidden from you; only relevant parts are shown, like the brakes, accelerator, and gearbox.% Row Count 6 (+ 4) } \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}{Generators}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{Generators are functions that return an iterable generator object. Because the values from the generator object are fetched one at a time rather than the entire list at once, you can use a for-loop, next(), or list() function to get the actual values. Generator functions act just like regular functions with just one difference that they use the Python yield keyword instead of return . \newline % Row Count 8 (+ 8) Code: \newline % Row Count 9 (+ 1) def test\_sequence(): \newline % Row Count 10 (+ 1) num = 0 \newline % Row Count 11 (+ 1) while num\textless{}10: \newline % Row Count 12 (+ 1) yield num \newline % Row Count 13 (+ 1) num += 1 \newline % Row Count 14 (+ 1) for i in test\_sequence(): \newline % Row Count 15 (+ 1) print(i, end=",") \newline % Row Count 16 (+ 1) Output: 0,1,2,3,4,5,6,7,8,9% Row Count 17 (+ 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}{Inheritance}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{The way we inherited a few qualities from our parents similarly, a class can also inherit the qualities from a parent class. \newline % Row Count 3 (+ 3) \{\{nl\}\}For eg: A Phone Class can have two Child Classes: 1) TelePhone \newline % Row Count 5 (+ 2) and 2) MobilePhone. Both can inherit the "calling" behaviour. \newline % Row Count 7 (+ 2) \{\{nl\}\}Different types of Inheritance: \newline % Row Count 8 (+ 1) ~~~~{\bf{Single inheritance:}} When a child class inherits from only one parent class, it is called single inheritance. We saw an example above. \newline % Row Count 12 (+ 4) ~~~~{\bf{Multiple inheritances:}} When a child class inherits from multiple parent classes, it is called multiple inheritances. \newline % Row Count 15 (+ 3) ~~~~{\bf{Multilevel inheritance:}} When we have a child and grandchild relationship. \newline % Row Count 18 (+ 3) ~~~~{\bf{Hierarchical inheritance:}} More than one derived class are created from a single base. \newline % Row Count 21 (+ 3) ~~~~{\bf{Hybrid inheritance:}} This form combines more than one form of inheritance. Basically, it is a blend of more than one type of inheritance.% Row Count 25 (+ 4) } \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}{Polymorphism}} \tn \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{It means many forms. With the same name, it provides different forms. \newline % Row Count 2 (+ 2) For eg: In Chess, we've 6 pieces - king, rook, bishop, queen, knight, and pawn. All of them "move" differently i.e. Bishop moves diagonally, Rooks move horizontally and vertically, etc.% Row Count 6 (+ 4) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}