\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{Termo} \pdfinfo{ /Title (pcap-31-0x.pdf) /Creator (Cheatography) /Author (Termo) /Subject (PCAP-31-0x 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}{1A75A3} \definecolor{LightBackground}{HTML}{F0F6F9} \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{PCAP-31-0x Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Termo} via \textcolor{DarkBackground}{\uline{cheatography.com/188474/cs/39313/}}} \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}Termo \\ \uline{cheatography.com/termo} \\ \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 28th June, 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*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Import Modules}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import math} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{import sys} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import math, sys} \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{from math import pi} \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from math import pi, sin} \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{import math as m} \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from math import pi as p} \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{from math import pi as PI, sin as sinus} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{1.04 cm} x{6.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Working with modules}} \tn % Row 0 \SetRowColor{LightBackground} dir() & list all entities within a module \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Random Module}} \tn % Row 0 \SetRowColor{LightBackground} from random import seed & seed(a=None, version=2) - initializes random number generator, a=None current time used \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} from random import random & random() - random float ranging 0.0\textless{}= X \textless{} 1.0 \tn % Row Count 6 (+ 2) % Row 2 \SetRowColor{LightBackground} from random import randrange & randrange(start, stop{[}, step{]}) \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} from random import randint & randint(a, b) - a \textless{}= N \textless{}= b. Alias for randrange(a, b+1) \tn % Row Count 11 (+ 3) % Row 4 \SetRowColor{LightBackground} from random import choice & choice(seq) - return random element \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} from random import sample & sample(population, k, *, counts=None) - return list of elements \tn % Row Count 16 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Platform Module}} \tn % Row 0 \SetRowColor{LightBackground} from platform import platform & platform(aliased=0, terse=0) - returns single stringe showing underlying platform \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} from platform import machine & machine() - return machine type e. g. 'AMD64' \tn % Row Count 8 (+ 3) % Row 2 \SetRowColor{LightBackground} from platform import processor & processor() - return real processor name 'amdk6' \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} from platform import system & system() - return OS name e. g. 'Windows', 'Linux' \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} from platform import version & version() - return system release \tn % Row Count 16 (+ 2) % Row 5 \SetRowColor{white} from platform import \seqsplit{python\_implementation} & \seqsplit{python\_implementation()} - return python version as string \seqsplit{'major.minor.patchlevel'} \tn % Row Count 21 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.36 cm} x{6.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Sorting}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{sorted()} & new list gets created \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{sort()} & performed in situ, changes the original list \tn % Row Count 4 (+ 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}{OOP - check attributes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{class Sampleclass: \newline a = 1 \newline def \_\_init\_\_(self): \newline self.b = 2 \newline \newline \newline object = Sampleclass() \newline \newline print(hasattr(object , 'b')) \newline print(hasattr(object , 'a')) \newline print(hasattr(Sampleclass, 'b')) \newline print(hasattr(Sampleclass, 'a'))} \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}{OOP - class variable}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{class Sampleclass: \newline     counter = 0 \newline     def \_\_init\_\_(self, var = 1): \newline         self.\_\_first = var \newline         Sampleclass.counter += 1} \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}{OOP - instance variable}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{class Sampleclass: \newline     def \_\_init\_\_(self, var = 1): \newline         self.first = var \newline \newline     def set\_second(self, var): \newline         self.second = var} \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}{Object Oriented Programming (OOP) - general}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{class is a set of objects} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{objects belongs to a class} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{object is incarnation of requirements, properties, qualities of a class} \tn % Row Count 4 (+ 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}{OOP - Method Vars}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{class Sample: \newline varia = 2 \newline def method(self): \newline print(self.varia, self.var) \newline \newline \newline obj = Sample() \newline obj.var = 3 \newline obj.method()} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.28 cm} x{4.72 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{OOP - Method Resolution Order (MRO)}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Way a language scans through the upper part of classes} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} class Bottom(Middle, Top) & works when Top created before Middle \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} class Bottom(Top, Middle) & fails when Top created before Middle \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.08 cm} x{5.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{OOP - Vars (some)}} \tn % Row 0 \SetRowColor{LightBackground} \_\_dict\_\_ & shows entities \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \_\_name\_\_ & name of class \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{\_\_module\_\_} & name of module \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} \_\_bases\_\_ & names of direct superclasses \tn % Row Count 4 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{1.84 cm} x{6.16 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{OOP - Sub/Superclass and Incarnation}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{issubclass()} & identifies relationship between 2 classes \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & each class considers itself to be a subclass of itself \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{isinstance()} & Checks if object is an incarnation of a class \tn % Row Count 6 (+ 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}{"Is" operator}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{checks whether two variables refer to the same object} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{variables don't store the object, they point to internal Python memory} \tn % Row Count 4 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.8 cm} x{5.2 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{OOP - Inheritance with more than one class}} \tn % Row 0 \SetRowColor{LightBackground} class Sub(Left, Right) & Python scans left to right \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & if vars duplicate, "Left" vars will be shown \tn % Row Count 4 (+ 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}{Generators and Iterators - general}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Generator produce a series of values and control iteration process (range())} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Iterator is an object conforming to iterator protocol (\_\_iter\_\_(), \_\_next\_\_())} \tn % Row Count 4 (+ 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}{Iterator with yield}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{FAILS \newline def func(n): \newline for i in range(n): \newline return i \newline \newline WORKS \newline def func(n): \newline for i in range(n): \newline yield i} \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}{List vs Generator}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\# list generated and iterated through: \newline for v in {[}1 if x \% 2 == 0 else 0 for x in range(10){]}: \newline print(v, end=" ") \newline print() \newline \newline \# subsequent values are generated one by one: \newline for v in (1 if x \% 2 == 0 else 0 for x in range(10)): \newline print(v, end=" ") \newline print()} \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}{File streams}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{read} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{write} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{update} \tn % Row Count 3 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{5.92 cm} x{2.08 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File streams open, close, std}} \tn % Row 0 \SetRowColor{LightBackground} open() & open stream \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} close() & close stream \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} standard streams with 'import sys' & sys.stdin \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} & \seqsplit{sys.stdout} \tn % Row Count 7 (+ 1) % Row 4 \SetRowColor{LightBackground} & \seqsplit{sys.stderr} \tn % Row Count 8 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.56 cm} x{5.44 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{File streams continued}} \tn % Row 0 \SetRowColor{LightBackground} 'r' & read mode \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} 'w' & write mode \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} 'a' & append mode \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} 'r+' & read and update mode \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} 'w+' & write and update mode \tn % Row Count 5 (+ 1) % Row 5 \SetRowColor{white} 'rt' / 'rb' & read text / binary \tn % Row Count 6 (+ 1) % Row 6 \SetRowColor{LightBackground} 'wt' / 'wb' & write text / binary \tn % Row Count 7 (+ 1) % Row 7 \SetRowColor{white} 'at' / 'ab' & append text / binary \tn % Row Count 8 (+ 1) % Row 8 \SetRowColor{LightBackground} 'r+t' / 'r+b' & read and update text/binary \tn % Row Count 10 (+ 2) % Row 9 \SetRowColor{white} 'w+t' / 'w+b' & write and update text/binary \tn % Row Count 12 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.64 cm} x{5.36 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{OS Moudle}} \tn % Row 0 \SetRowColor{LightBackground} os.uname() & doesn't work with Windows \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} os.name() & works with Windows \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} os.listdir() & print directories \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} os.mkdir() & create directory \tn % Row Count 4 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{os.makedirs()} & create multiple directories \tn % Row Count 6 (+ 2) % Row 5 \SetRowColor{white} os.chdir() & change directory \tn % Row Count 7 (+ 1) % Row 6 \SetRowColor{LightBackground} os.getcwd() & show current directory \tn % Row Count 8 (+ 1) % Row 7 \SetRowColor{white} os.rmdir() & delete directory \tn % Row Count 9 (+ 1) % Row 8 \SetRowColor{LightBackground} \seqsplit{os.removedirs()} & removes directories recursively \tn % Row Count 11 (+ 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}{Datetime Module - Class Date}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from datetime import date \newline \newline v\_today = date.today() \newline \newline print(v\_today.year) \newline print(v\_today.month) \newline print(v\_today.day) \newline print(v\_today.today) \newline \newline \#\#\# \newline \newline from datetime import date \newline \newline d = date(2019, 11, 4) \newline print(d.weekday()) \newline print(d.isoweekday())} \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}{Datetime Module - Class Time}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from datetime import time \newline \newline t = time(14, 53, 20, 1) \newline \newline print("Time:", t) \newline print("Hour:", t.hour) \newline print("Minute:", t.minute) \newline print("Second:", t.second) \newline print("Microsecond:", t.microsecond)} \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}{Time Module - asctime() and mktime() functions}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import time \newline \newline timestamp = 1572879180 \newline st = time.gmtime(timestamp) \newline \newline print(time.asctime(st)) \newline print(time.mktime((2019, 11, 4, 14, 53, 0, 0, 308, 0)))} \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}{Date and time operations}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from datetime import date \newline from datetime import datetime \newline \newline d1 = date(2020, 11, 4) \newline d2 = date(2019, 11, 4) \newline \newline print(d1 - d2) \newline \newline dt1 = datetime(2020, 11, 4, 0, 0, 0) \newline dt2 = datetime(2019, 11, 4, 14, 53, 0) \newline \newline print(dt1 - dt2)} \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}{Calendar Module}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import calendar \newline \newline print(calendar.calendar(2023)) \newline calendar.prcal(2023)} \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}{Calender for a month}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import calendar \newline print(calendar.month(2020, 11))} \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}{Calendar Objects}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import calendar \newline \newline c = \seqsplit{calendar.Calendar(calendar.SUNDAY)} \newline \newline for weekday in c.iterweekdays(): \newline print(weekday, end=" ")} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.12 cm} x{4.88 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Calender Create Classes}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{calender.Calender} & provides methods for calender data formatting \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{calendar.TextCalendar} & create text calendars \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{calendar.HTMLCalendar} & create HTML calendars \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{calendar.LocalTextCalendar} & subclass (see above) uses local parameter \tn % Row Count 8 (+ 2) % Row 4 \SetRowColor{LightBackground} \seqsplit{calendar.LocalHTMLCalendar} & subclass (see above) uses local parameter \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}{Calender set first week day}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import calendar \newline \newline calendar.setfirstweekday(calendar.SUNDAY) \newline calendar.prmonth(2020, 12)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.96 cm} x{5.04 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{PIP}} \tn % Row 0 \SetRowColor{LightBackground} pip -{}-version & show pip version (pip version 2) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} pip3 -{}-version & show pip version (pip version 3) \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} pip help & show pip commands \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} pip help operation & show info about a specific operation \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} pip show package\_name & show info about installed package \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} pip search string & search for a package \tn % Row Count 11 (+ 2) % Row 6 \SetRowColor{LightBackground} pip install package & package installation \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.6 cm} x{4.4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String Operations}} \tn % Row 0 \SetRowColor{LightBackground} ord() & ordinal, code point \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} chr() & character \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} possible operations & indexing, iterating, slicing, 'in' and 'not' operators \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} impossible operations (immutable) & append, del, insert \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} max(), min() & uses ASCII value \tn % Row Count 8 (+ 1) % Row 5 \SetRowColor{white} additional operations & index(), list(), count() \tn % Row Count 10 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String Methods}} \tn % Row 0 \SetRowColor{LightBackground} capitalize() & stRiNGdiNg -\textgreater{} stRiNGdiNg \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} endswith(suffix{[}, start{[}, end{]}{]}) & \seqsplit{'stringding'.endswith('ding')} return True \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} find(sub{[}, start{[}, end{]}{]}) & \seqsplit{'stringding'.find('in')} return 3 (index \#) \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} isalum() & 'string10' -\textgreater{} True, 'string\_10' -\textgreater{} False \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} isalpha() & 'string' -\textgreater{} True, 'string10' -\textgreater{} False \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} isdigit() & '10' -\textgreater{} True, 'string10' -\textgreater{} False \tn % Row Count 14 (+ 2) % Row 6 \SetRowColor{LightBackground} islower() & 'stringding' -\textgreater{} True, 'strinGDing' -\textgreater{} False \tn % Row Count 17 (+ 3) % Row 7 \SetRowColor{white} isspace() & ' \textbackslash{}n ' -\textgreater{} True, ' ' -\textgreater{} True, 'string ding' -\textgreater{} False \tn % Row Count 20 (+ 3) % Row 8 \SetRowColor{LightBackground} isupper() & 'string' -\textgreater{} False, 'stRINg' -\textgreater{} False, 'STRING' -\textgreater{} True \tn % Row Count 23 (+ 3) % Row 9 \SetRowColor{white} join() & ",".join({[}'li', 'st', 'joined'{]} -\textgreater{} 'li,st,joined' \tn % Row Count 26 (+ 3) % Row 10 \SetRowColor{LightBackground} lower() & 'stRinGDing' -\textgreater{}'stringding' \tn % Row Count 28 (+ 2) % Row 11 \SetRowColor{white} lstrip(str) & \seqsplit{'stringding'.lstrip('str')} -\textgreater{} 'ingding' \tn % Row Count 30 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String Methods (cont)}} \tn % Row 12 \SetRowColor{LightBackground} rstrip(str) & \seqsplit{'stringding'.rstrip('ding')} -\textgreater{} 'str' \tn % Row Count 2 (+ 2) % Row 13 \SetRowColor{white} replace(old, new{[}, count{]}) & \seqsplit{'stringding'.lstrip('str')} -\textgreater{} 'strAngdAng' \tn % Row Count 5 (+ 3) % Row 14 \SetRowColor{LightBackground} rfind(sub{[}, start{[}, end{]}{]}) & \seqsplit{'stringding'.rfind('n')} -\textgreater{} 8, ('n', 5) -\textgreater{} 8, ('n', 10) -\textgreater{} -1 (failure) \tn % Row Count 9 (+ 4) % Row 15 \SetRowColor{white} split(str) & \seqsplit{'stringding'.split('i')} -\textgreater{} {[}'str', 'ngd', 'ng'{]} \tn % Row Count 12 (+ 3) % Row 16 \SetRowColor{LightBackground} startswith(str) & \seqsplit{'stringding'.startswith('str')} -\textgreater{} True, \seqsplit{'stringding'.startswith('ring')} -\textgreater{} False \tn % Row Count 16 (+ 4) % Row 17 \SetRowColor{white} strip() remove leading, trailing whitespaces & ' stringding ' -\textgreater{} 'stringding' \tn % Row Count 19 (+ 3) % Row 18 \SetRowColor{LightBackground} swapcase() & 'strinGDiNg' -\textgreater{} 'STRINgdInG' \tn % Row Count 21 (+ 2) % Row 19 \SetRowColor{white} title() & 'this Is a title' -\textgreater{} 'This Is A Title' \tn % Row Count 23 (+ 2) % Row 20 \SetRowColor{LightBackground} upper() & 'strinGDiNg' -\textgreater{} 'STRINGDING' \tn % Row Count 25 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{String Comparison}} \tn % Row 0 \SetRowColor{LightBackground} Compare & ==, !=, \textless{}, \textgreater{}, \textless{}=, \textgreater{}= \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} string == number & False \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} string != umber & True \tn % Row Count 3 (+ 1) % Row 3 \SetRowColor{white} string \textgreater{}= number & Exception \tn % Row Count 4 (+ 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}{OOP - Method Invocation}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{class Sample: \newline def other(self): \newline print("other") \newline \newline def method(self): \newline print("method") \newline self.other() \newline \newline \newline obj = Sample() \newline obj.method()} \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}{OOP - Constructor}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{class Sample: \newline % Row Count 1 (+ 1) def \_\_init\_\_(self, value = None): \newline % Row Count 2 (+ 1) self.var = value \newline % Row Count 3 (+ 1) obj\_1 = Sample("object") \newline % Row Count 4 (+ 1) obj\_2 = Sample() \newline % Row Count 5 (+ 1) print(obj\_1.var) \newline % Row Count 6 (+ 1) print(obj\_2.var)% Row Count 7 (+ 1) } \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}{OOP - Hiding}} \tn \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{class Sample: \newline % Row Count 1 (+ 1) def visible(self): \newline % Row Count 2 (+ 1) print("visible") \newline % Row Count 3 (+ 1) def \_\_hidden(self): \newline % Row Count 4 (+ 1) print("hidden") \newline % Row Count 5 (+ 1) obj = Sample() \newline % Row Count 6 (+ 1) obj.visible() \newline % Row Count 7 (+ 1) try: \newline % Row Count 8 (+ 1) obj.\_\_hidden() \newline % Row Count 9 (+ 1) except: \newline % Row Count 10 (+ 1) print("failed") \newline % Row Count 11 (+ 1) obj.\_Sample\_\_hidden()% Row Count 12 (+ 1) } \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}{Exception continued}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{try: \newline this is what we want \newline except: \newline this is what we do with errors \newline else: \newline we do this when no exception has been raised and our "try" was successful \newline final: \newline no matter of what the outcome is we do that} \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}{Exceptions are classes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{try: \newline raise Exception \newline except Exception as e: \newline print(e, e.\_\_str\_\_(), e.args)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.08 cm} x{3.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Lambda}} \tn % Row 0 \SetRowColor{LightBackground} lambda parameter: expression & lambda x: x * 2 \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & lambda x, y: x * y \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} & lambda x, y, z: (x * y) / z \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.16 cm} x{5.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{map() function}} \tn % Row 0 \SetRowColor{LightBackground} map(arg1, arg2) & list = list(map(lambda x: x * 2, sourcelist)) \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} arg1 & a function what to do \tn % Row Count 3 (+ 1) % Row 2 \SetRowColor{LightBackground} arg2 & iterable object (list, tuple, generator, ...) \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.48 cm} x{5.52 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{filter() function}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{filter items based on a given statement} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} filter(arg1, arg2) & list = list(filter(lambda x: x \textgreater{} 2, sourcelist)) \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} arg1 & function to what to filter \tn % Row Count 4 (+ 1) % Row 3 \SetRowColor{white} arg2 & iterable object (list, tuple, generator, ...) \tn % Row Count 6 (+ 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}{Conditional Expression}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{print(True if 0 ≥ 0 else False)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.08 cm} x{5.92 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Work with files}} \tn % Row 0 \SetRowColor{LightBackground} read(1) & read chars -\textgreater{} 1 byte chunks \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} read() & read chars all at once \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \seqsplit{readline(10)} & read lines -\textgreater{} 10 byte chunks \tn % Row Count 4 (+ 2) % Row 3 \SetRowColor{white} \seqsplit{readline()} & read full line \tn % Row Count 5 (+ 1) % Row 4 \SetRowColor{LightBackground} \seqsplit{readlines(10)} & read all lines -\textgreater{} 10 byte size chunks \tn % Row Count 7 (+ 2) % Row 5 \SetRowColor{white} \seqsplit{readlines()} & read all lines \tn % Row Count 9 (+ 2) % Row 6 \SetRowColor{LightBackground} \seqsplit{write(arg1)} & write to a file \tn % Row Count 11 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.88 cm} x{5.12 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Bytearray}} \tn % Row 0 \SetRowColor{LightBackground} data = bytearray(10) & creates a bytearray filled with 0's \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} & are mutable, len(), index() \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} & only integers, only 0 to 255 \tn % Row Count 6 (+ 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}{Bytearray - write to binary file}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from os import strerror \newline \newline data = bytearray(10) \newline \newline for i in range(len(data)): \newline data{[}i{]} = 10 + i \newline \newline try: \newline bf = open('file.bin', 'wb') \newline bf.write(data) \newline bf.close() \newline except IOError as e: \newline print("I/O error occurred:", strerror(e.errno))} \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}{Bytearray - read from binary file}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from os import strerror \newline \newline data = bytearray(10) \newline \newline try: \newline binary\_file = open('file.bin', 'rb') \newline \seqsplit{binary\_file.readinto(data)} \# file.read(data) would also work \newline binary\_file.close() \newline \newline for b in data: \newline print(hex(b), end=' ') \newline except IOError as e: \newline print("I/O error occurred:", strerror(e.errno))} \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}{Time Module}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import time \newline \newline timestamp = 1572879180 \newline print(time.ctime(timestamp)) \newline print(time.gmtime(timestamp)) \newline print(time.localtime(timestamp)) \newline \newline print(time.ctime())} \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}{timestamp()}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from datetime import datetime \newline \newline dt = datetime(2020, 10, 4, 14, 55) \newline print("Timestamp:", dt.timestamp())} \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}{strftime()}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from datetime import time \newline from datetime import datetime \newline \newline t = time(14, 53) \newline print(t.strftime("\%H:\%M:\%S")) \newline \newline dt = datetime(2020, 11, 4, 14, 53) \newline print(dt.strftime("\%y/\%B/\%d \%H:\%M:\%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}{stftime() in Time Module}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import time \newline \newline timestamp = 1572879180 \newline st = time.gmtime(timestamp) \newline \newline print(time.strftime("\%Y/\%m/\%d \%H:\%M:\%S", st)) \newline print(time.strftime("\%Y/\%m/\%d \%H:\%M:\%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}{timedelta()}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{from datetime import timedelta \newline \newline delta = timedelta(weeks=2, days=2, hours=3) \newline print(delta) \newline print("Days:", delta.days) \newline print("Seconds:", delta.seconds) \newline print("Microseconds:", delta.microseconds) \newline \newline \#\#\# \newline \newline from datetime import timedelta \newline from datetime import date \newline from datetime import datetime \newline \newline delta = timedelta(weeks=2, days=2, hours=2) \newline print(delta) \newline \newline delta2 = delta * 2 \newline print(delta2) \newline \newline d = date(2019, 10, 4) + delta2 \newline print(d) \newline \newline dt = datetime(2019, 10, 4, 14, 53) + delta2 \newline print(dt)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{2.4 cm} x{5.6 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Calender Iterators}} \tn % Row 0 \SetRowColor{LightBackground} \seqsplit{itermonthdates()} & returns days of the week as int \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \seqsplit{itermonthdates2()} & return tuple day of the month int and week day int \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \seqsplit{itermonthdays3()} & return days as tuple year int, month int, day of month int \tn % Row Count 7 (+ 3) % Row 3 \SetRowColor{white} \seqsplit{itermonthdays4()} & return days as tuple with year int, month int day of month int, day of week int \tn % Row Count 10 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Leap Year}} \tn % Row 0 \SetRowColor{LightBackground} isleap(\textless{}year\textgreater{}) & Check is year specified is leap year \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} leapdays(\textless{}year1, year2\textgreater{}) & returns number of lead years in specified range \tn % Row Count 4 (+ 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}{Calender weekday()}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import calendar \newline print(calendar.weekday(2020, 12, 24))} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}