diff options
| author | Christian Kolset <christian.kolset@gmail.com> | 2025-04-22 16:26:11 -0600 |
|---|---|---|
| committer | Christian Kolset <christian.kolset@gmail.com> | 2025-04-22 16:26:11 -0600 |
| commit | ec6f7800ee9afd2cf354b05883502a0a327561d2 (patch) | |
| tree | 2dcce6d294dbed8b165ecb5103d0c2f7a1e1a220 /tutorials/module_1/latex/basics_of_python.tex | |
| parent | f2f717926692c18f51e172de3aa22360620c7250 (diff) | |
Added latex files
Diffstat (limited to 'tutorials/module_1/latex/basics_of_python.tex')
| -rw-r--r-- | tutorials/module_1/latex/basics_of_python.tex | 703 |
1 files changed, 703 insertions, 0 deletions
diff --git a/tutorials/module_1/latex/basics_of_python.tex b/tutorials/module_1/latex/basics_of_python.tex new file mode 100644 index 0000000..89dd745 --- /dev/null +++ b/tutorials/module_1/latex/basics_of_python.tex @@ -0,0 +1,703 @@ +\documentclass[11pt]{article} + + \usepackage[breakable]{tcolorbox} + \usepackage{parskip} % Stop auto-indenting (to mimic markdown behaviour) + \author{Christian Kolset} + + % Basic figure setup, for now with no caption control since it's done + % automatically by Pandoc (which extracts  syntax from Markdown). + \usepackage{graphicx} + % Keep aspect ratio if custom image width or height is specified + \setkeys{Gin}{keepaspectratio} + % Maintain compatibility with old templates. Remove in nbconvert 6.0 + \let\Oldincludegraphics\includegraphics + % Ensure that by default, figures have no caption (until we provide a + % proper Figure object with a Caption API and a way to capture that + % in the conversion process - todo). + \usepackage{caption} + \DeclareCaptionFormat{nocaption}{} + \captionsetup{format=nocaption,aboveskip=0pt,belowskip=0pt} + + \usepackage{float} + \floatplacement{figure}{H} % forces figures to be placed at the correct location + \usepackage{xcolor} % Allow colors to be defined + \usepackage{enumerate} % Needed for markdown enumerations to work + \usepackage{geometry} % Used to adjust the document margins + \usepackage{amsmath} % Equations + \usepackage{amssymb} % Equations + \usepackage{textcomp} % defines textquotesingle + + % Hack from http://tex.stackexchange.com/a/47451/13684: + \AtBeginDocument{% + \def\PYZsq{\textquotesingle}% Upright quotes in Pygmentized code + } + \usepackage{upquote} % Upright quotes for verbatim code + \usepackage{eurosym} % defines \euro + + \usepackage{iftex} + \ifPDFTeX + \usepackage[T1]{fontenc} + \IfFileExists{alphabeta.sty}{ + \usepackage{alphabeta} + }{ + \usepackage[mathletters]{ucs} + \usepackage[utf8]{inputenc} + } + \else + \usepackage{fontspec} + \usepackage{unicode-math} + \fi + + \usepackage{fancyvrb} % verbatim replacement that allows latex + \usepackage{grffile} % extends the file name processing of package graphics + % to support a larger range + \makeatletter % fix for old versions of grffile with XeLaTeX + \@ifpackagelater{grffile}{2019/11/01} + { + % Do nothing on new versions + } + { + \def\Gread@@xetex#1{% + \IfFileExists{"\Gin@base".bb}% + {\Gread@eps{\Gin@base.bb}}% + {\Gread@@xetex@aux#1}% + } + } + \makeatother + \usepackage[Export]{adjustbox} % Used to constrain images to a maximum size + \adjustboxset{max size={0.9\linewidth}{0.9\paperheight}} + + % The hyperref package gives us a pdf with properly built + % internal navigation ('pdf bookmarks' for the table of contents, + % internal cross-reference links, web links for URLs, etc.) + \usepackage{hyperref} + % The default LaTeX title has an obnoxious amount of whitespace. By default, + % titling removes some of it. It also provides customization options. + \usepackage{titling} + \usepackage{longtable} % longtable support required by pandoc >1.10 + \usepackage{booktabs} % table support for pandoc > 1.12.2 + \usepackage{array} % table support for pandoc >= 2.11.3 + \usepackage{calc} % table minipage width calculation for pandoc >= 2.11.1 + \usepackage[inline]{enumitem} % IRkernel/repr support (it uses the enumerate* environment) + \usepackage[normalem]{ulem} % ulem is needed to support strikethroughs (\sout) + % normalem makes italics be italics, not underlines + \usepackage{soul} % strikethrough (\st) support for pandoc >= 3.0.0 + \usepackage{mathrsfs} + + + + % Colors for the hyperref package + \definecolor{urlcolor}{rgb}{0,.145,.698} + \definecolor{linkcolor}{rgb}{.71,0.21,0.01} + \definecolor{citecolor}{rgb}{.12,.54,.11} + + % ANSI colors + \definecolor{ansi-black}{HTML}{3E424D} + \definecolor{ansi-black-intense}{HTML}{282C36} + \definecolor{ansi-red}{HTML}{E75C58} + \definecolor{ansi-red-intense}{HTML}{B22B31} + \definecolor{ansi-green}{HTML}{00A250} + \definecolor{ansi-green-intense}{HTML}{007427} + \definecolor{ansi-yellow}{HTML}{DDB62B} + \definecolor{ansi-yellow-intense}{HTML}{B27D12} + \definecolor{ansi-blue}{HTML}{208FFB} + \definecolor{ansi-blue-intense}{HTML}{0065CA} + \definecolor{ansi-magenta}{HTML}{D160C4} + \definecolor{ansi-magenta-intense}{HTML}{A03196} + \definecolor{ansi-cyan}{HTML}{60C6C8} + \definecolor{ansi-cyan-intense}{HTML}{258F8F} + \definecolor{ansi-white}{HTML}{C5C1B4} + \definecolor{ansi-white-intense}{HTML}{A1A6B2} + \definecolor{ansi-default-inverse-fg}{HTML}{FFFFFF} + \definecolor{ansi-default-inverse-bg}{HTML}{000000} + + % common color for the border for error outputs. + \definecolor{outerrorbackground}{HTML}{FFDFDF} + + % commands and environments needed by pandoc snippets + % extracted from the output of `pandoc -s` + \providecommand{\tightlist}{% + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} + \DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}} + % Add ',fontsize=\small' for more characters per line + \newenvironment{Shaded}{}{} + \newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} + \newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{{#1}}} + \newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} + \newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} + \newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{{#1}}} + \newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} + \newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} + \newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{{#1}}}} + \newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{{#1}}} + \newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} + \newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{{#1}}} + \newcommand{\RegionMarkerTok}[1]{{#1}} + \newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{{#1}}}} + \newcommand{\NormalTok}[1]{{#1}} + + % Additional commands for more recent versions of Pandoc + \newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{{#1}}} + \newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} + \newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{{#1}}} + \newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{{#1}}} + \newcommand{\ImportTok}[1]{{#1}} + \newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{{#1}}}} + \newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} + \newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} + \newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{{#1}}} + \newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{{#1}}}} + \newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{{#1}}} + \newcommand{\BuiltInTok}[1]{{#1}} + \newcommand{\ExtensionTok}[1]{{#1}} + \newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{{#1}}} + \newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{{#1}}} + \newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} + \newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{{#1}}}}} + \makeatletter + \newsavebox\pandoc@box + \newcommand*\pandocbounded[1]{% + \sbox\pandoc@box{#1}% + % scaling factors for width and height + \Gscale@div\@tempa\textheight{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb\linewidth{\wd\pandoc@box}% + % select the smaller of both + \ifdim\@tempb\p@<\@tempa\p@ + \let\@tempa\@tempb + \fi + % scaling accordingly (\@tempa < 1) + \ifdim\@tempa\p@<\p@ + \scalebox{\@tempa}{\usebox\pandoc@box}% + % scaling not needed, use as it is + \else + \usebox{\pandoc@box}% + \fi + } + \makeatother + + % Define a nice break command that doesn't care if a line doesn't already + % exist. + \def\br{\hspace*{\fill} \\* } + % Math Jax compatibility definitions + \def\gt{>} + \def\lt{<} + \let\Oldtex\TeX + \let\Oldlatex\LaTeX + \renewcommand{\TeX}{\textrm{\Oldtex}} + \renewcommand{\LaTeX}{\textrm{\Oldlatex}} + % Document parameters + % Document title + \title{basics\_of\_python} + + + + + + + +% Pygments definitions +\makeatletter +\def\PY@reset{\let\PY@it=\relax \let\PY@bf=\relax% + \let\PY@ul=\relax \let\PY@tc=\relax% + \let\PY@bc=\relax \let\PY@ff=\relax} +\def\PY@tok#1{\csname PY@tok@#1\endcsname} +\def\PY@toks#1+{\ifx\relax#1\empty\else% + \PY@tok{#1}\expandafter\PY@toks\fi} +\def\PY@do#1{\PY@bc{\PY@tc{\PY@ul{% + \PY@it{\PY@bf{\PY@ff{#1}}}}}}} +\def\PY#1#2{\PY@reset\PY@toks#1+\relax+\PY@do{#2}} + +\@namedef{PY@tok@w}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.73,0.73}{##1}}} +\@namedef{PY@tok@c}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PY@tok@cp}{\def\PY@tc##1{\textcolor[rgb]{0.61,0.40,0.00}{##1}}} +\@namedef{PY@tok@k}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@kp}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@kt}{\def\PY@tc##1{\textcolor[rgb]{0.69,0.00,0.25}{##1}}} +\@namedef{PY@tok@o}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@ow}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PY@tok@nb}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@nf}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PY@tok@nc}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PY@tok@nn}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PY@tok@ne}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.80,0.25,0.22}{##1}}} +\@namedef{PY@tok@nv}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PY@tok@no}{\def\PY@tc##1{\textcolor[rgb]{0.53,0.00,0.00}{##1}}} +\@namedef{PY@tok@nl}{\def\PY@tc##1{\textcolor[rgb]{0.46,0.46,0.00}{##1}}} +\@namedef{PY@tok@ni}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PY@tok@na}{\def\PY@tc##1{\textcolor[rgb]{0.41,0.47,0.13}{##1}}} +\@namedef{PY@tok@nt}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@nd}{\def\PY@tc##1{\textcolor[rgb]{0.67,0.13,1.00}{##1}}} +\@namedef{PY@tok@s}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@sd}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@si}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PY@tok@se}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.67,0.36,0.12}{##1}}} +\@namedef{PY@tok@sr}{\def\PY@tc##1{\textcolor[rgb]{0.64,0.35,0.47}{##1}}} +\@namedef{PY@tok@ss}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PY@tok@sx}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@m}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@gh}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PY@tok@gu}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.50,0.00,0.50}{##1}}} +\@namedef{PY@tok@gd}{\def\PY@tc##1{\textcolor[rgb]{0.63,0.00,0.00}{##1}}} +\@namedef{PY@tok@gi}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.52,0.00}{##1}}} +\@namedef{PY@tok@gr}{\def\PY@tc##1{\textcolor[rgb]{0.89,0.00,0.00}{##1}}} +\@namedef{PY@tok@ge}{\let\PY@it=\textit} +\@namedef{PY@tok@gs}{\let\PY@bf=\textbf} +\@namedef{PY@tok@gp}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,0.50}{##1}}} +\@namedef{PY@tok@go}{\def\PY@tc##1{\textcolor[rgb]{0.44,0.44,0.44}{##1}}} +\@namedef{PY@tok@gt}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.27,0.87}{##1}}} +\@namedef{PY@tok@err}{\def\PY@bc##1{{\setlength{\fboxsep}{\string -\fboxrule}\fcolorbox[rgb]{1.00,0.00,0.00}{1,1,1}{\strut ##1}}}} +\@namedef{PY@tok@kc}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@kd}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@kn}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@kr}{\let\PY@bf=\textbf\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@bp}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.50,0.00}{##1}}} +\@namedef{PY@tok@fm}{\def\PY@tc##1{\textcolor[rgb]{0.00,0.00,1.00}{##1}}} +\@namedef{PY@tok@vc}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PY@tok@vg}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PY@tok@vi}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PY@tok@vm}{\def\PY@tc##1{\textcolor[rgb]{0.10,0.09,0.49}{##1}}} +\@namedef{PY@tok@sa}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@sb}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@sc}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@dl}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@s2}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@sh}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@s1}{\def\PY@tc##1{\textcolor[rgb]{0.73,0.13,0.13}{##1}}} +\@namedef{PY@tok@mb}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@mf}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@mh}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@mi}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@il}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@mo}{\def\PY@tc##1{\textcolor[rgb]{0.40,0.40,0.40}{##1}}} +\@namedef{PY@tok@ch}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PY@tok@cm}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PY@tok@cpf}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PY@tok@c1}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} +\@namedef{PY@tok@cs}{\let\PY@it=\textit\def\PY@tc##1{\textcolor[rgb]{0.24,0.48,0.48}{##1}}} + +\def\PYZbs{\char`\\} +\def\PYZus{\char`\_} +\def\PYZob{\char`\{} +\def\PYZcb{\char`\}} +\def\PYZca{\char`\^} +\def\PYZam{\char`\&} +\def\PYZlt{\char`\<} +\def\PYZgt{\char`\>} +\def\PYZsh{\char`\#} +\def\PYZpc{\char`\%} +\def\PYZdl{\char`\$} +\def\PYZhy{\char`\-} +\def\PYZsq{\char`\'} +\def\PYZdq{\char`\"} +\def\PYZti{\char`\~} +% for compatibility with earlier versions +\def\PYZat{@} +\def\PYZlb{[} +\def\PYZrb{]} +\makeatother + + + % For linebreaks inside Verbatim environment from package fancyvrb. + \makeatletter + \newbox\Wrappedcontinuationbox + \newbox\Wrappedvisiblespacebox + \newcommand*\Wrappedvisiblespace {\textcolor{red}{\textvisiblespace}} + \newcommand*\Wrappedcontinuationsymbol {\textcolor{red}{\llap{\tiny$\m@th\hookrightarrow$}}} + \newcommand*\Wrappedcontinuationindent {3ex } + \newcommand*\Wrappedafterbreak {\kern\Wrappedcontinuationindent\copy\Wrappedcontinuationbox} + % Take advantage of the already applied Pygments mark-up to insert + % potential linebreaks for TeX processing. + % {, <, #, %, $, ' and ": go to next line. + % _, }, ^, &, >, - and ~: stay at end of broken line. + % Use of \textquotesingle for straight quote. + \newcommand*\Wrappedbreaksatspecials {% + \def\PYGZus{\discretionary{\char`\_}{\Wrappedafterbreak}{\char`\_}}% + \def\PYGZob{\discretionary{}{\Wrappedafterbreak\char`\{}{\char`\{}}% + \def\PYGZcb{\discretionary{\char`\}}{\Wrappedafterbreak}{\char`\}}}% + \def\PYGZca{\discretionary{\char`\^}{\Wrappedafterbreak}{\char`\^}}% + \def\PYGZam{\discretionary{\char`\&}{\Wrappedafterbreak}{\char`\&}}% + \def\PYGZlt{\discretionary{}{\Wrappedafterbreak\char`\<}{\char`\<}}% + \def\PYGZgt{\discretionary{\char`\>}{\Wrappedafterbreak}{\char`\>}}% + \def\PYGZsh{\discretionary{}{\Wrappedafterbreak\char`\#}{\char`\#}}% + \def\PYGZpc{\discretionary{}{\Wrappedafterbreak\char`\%}{\char`\%}}% + \def\PYGZdl{\discretionary{}{\Wrappedafterbreak\char`\$}{\char`\$}}% + \def\PYGZhy{\discretionary{\char`\-}{\Wrappedafterbreak}{\char`\-}}% + \def\PYGZsq{\discretionary{}{\Wrappedafterbreak\textquotesingle}{\textquotesingle}}% + \def\PYGZdq{\discretionary{}{\Wrappedafterbreak\char`\"}{\char`\"}}% + \def\PYGZti{\discretionary{\char`\~}{\Wrappedafterbreak}{\char`\~}}% + } + % Some characters . , ; ? ! / are not pygmentized. + % This macro makes them "active" and they will insert potential linebreaks + \newcommand*\Wrappedbreaksatpunct {% + \lccode`\~`\.\lowercase{\def~}{\discretionary{\hbox{\char`\.}}{\Wrappedafterbreak}{\hbox{\char`\.}}}% + \lccode`\~`\,\lowercase{\def~}{\discretionary{\hbox{\char`\,}}{\Wrappedafterbreak}{\hbox{\char`\,}}}% + \lccode`\~`\;\lowercase{\def~}{\discretionary{\hbox{\char`\;}}{\Wrappedafterbreak}{\hbox{\char`\;}}}% + \lccode`\~`\:\lowercase{\def~}{\discretionary{\hbox{\char`\:}}{\Wrappedafterbreak}{\hbox{\char`\:}}}% + \lccode`\~`\?\lowercase{\def~}{\discretionary{\hbox{\char`\?}}{\Wrappedafterbreak}{\hbox{\char`\?}}}% + \lccode`\~`\!\lowercase{\def~}{\discretionary{\hbox{\char`\!}}{\Wrappedafterbreak}{\hbox{\char`\!}}}% + \lccode`\~`\/\lowercase{\def~}{\discretionary{\hbox{\char`\/}}{\Wrappedafterbreak}{\hbox{\char`\/}}}% + \catcode`\.\active + \catcode`\,\active + \catcode`\;\active + \catcode`\:\active + \catcode`\?\active + \catcode`\!\active + \catcode`\/\active + \lccode`\~`\~ + } + \makeatother + + \let\OriginalVerbatim=\Verbatim + \makeatletter + \renewcommand{\Verbatim}[1][1]{% + %\parskip\z@skip + \sbox\Wrappedcontinuationbox {\Wrappedcontinuationsymbol}% + \sbox\Wrappedvisiblespacebox {\FV@SetupFont\Wrappedvisiblespace}% + \def\FancyVerbFormatLine ##1{\hsize\linewidth + \vtop{\raggedright\hyphenpenalty\z@\exhyphenpenalty\z@ + \doublehyphendemerits\z@\finalhyphendemerits\z@ + \strut ##1\strut}% + }% + % If the linebreak is at a space, the latter will be displayed as visible + % space at end of first line, and a continuation symbol starts next line. + % Stretch/shrink are however usually zero for typewriter font. + \def\FV@Space {% + \nobreak\hskip\z@ plus\fontdimen3\font minus\fontdimen4\font + \discretionary{\copy\Wrappedvisiblespacebox}{\Wrappedafterbreak} + {\kern\fontdimen2\font}% + }% + + % Allow breaks at special characters using \PYG... macros. + \Wrappedbreaksatspecials + % Breaks at punctuation characters . , ; ? ! and / need catcode=\active + \OriginalVerbatim[#1,codes*=\Wrappedbreaksatpunct]% + } + \makeatother + + % Exact colors from NB + \definecolor{incolor}{HTML}{303F9F} + \definecolor{outcolor}{HTML}{D84315} + \definecolor{cellborder}{HTML}{CFCFCF} + \definecolor{cellbackground}{HTML}{F7F7F7} + + % prompt + \makeatletter + \newcommand{\boxspacing}{\kern\kvtcb@left@rule\kern\kvtcb@boxsep} + \makeatother + \newcommand{\prompt}[4]{ + {\ttfamily\llap{{\color{#2}[#3]:\hspace{3pt}#4}}\vspace{-\baselineskip}} + } + + + + % Prevent overflowing lines due to hard-to-break entities + \sloppy + % Setup hyperref package + \hypersetup{ + breaklinks=true, % so long urls are correctly broken across lines + colorlinks=true, + urlcolor=urlcolor, + linkcolor=linkcolor, + citecolor=citecolor, + } + % Slightly bigger margins than the latex defaults + + \geometry{verbose,tmargin=1in,bmargin=1in,lmargin=1in,rmargin=1in} + + + +\begin{document} + + \maketitle + + + + + \hypertarget{basics-of-python}{ +\section{Basics of Python}\label{basics-of-python}} + +This page contains important fundamental concepts used in Python such as +syntax, operators, order or precedence and more. + + \hypertarget{syntax}{% +\subsection{Syntax}\label{syntax}} + +\hypertarget{indentations-and-blocks}{% +\subsubsection{Indentations and blocks}\label{indentations-and-blocks}} + +In python \emph{indentations} or the space at the start of each line, +signifies a block of code. This becomes important when we start working +with function and loops. We will talk more about this in the controls +structures tutorial. + +\hypertarget{comments}{% +\subsubsection{Comments}\label{comments}} + +Comments can be added to your code using the hash operator (\#). Any +text behind the comment operator till the end of the line will be +rendered as a comment. If you have an entire block of text or code that +needs to be commented out, the triple quotation marks (""") can be used. +Once used all the code after it will be considered a comment until the +comment is ended with the triple quotation marks. + + \hypertarget{operators}{% +\subsection{Operators}\label{operators}} + +In python, operators are special symbols or keywords that perform +operations on values or variables. This section covers some of the most +common operator that you will see in this course. + +\hypertarget{arithmetic-operators}{% +\subsubsection{Arithmetic operators}\label{arithmetic-operators}} + +\begin{longtable}[]{@{}ll@{}} +\toprule +Operator & Name \\ +\midrule +\endhead ++ & Addition \\ +- & Subtraction \\ +* & Multiplication \\ +/ & Division \\ +\% & Modulus \\ +** & Exponentiation \\ +// & Floor division \\ +\bottomrule +\end{longtable} + +\hypertarget{comparison-operators}{% +\subsubsection{Comparison operators}\label{comparison-operators}} + +Used in conditional statements such as \texttt{if} statements or +\texttt{while} loops. Note that in the computer world a double equal +sign (\texttt{==}) means \emph{is equal to}, where as the single equal +sign assigns the variable or defines the variable to be something. + +\begin{longtable}[]{@{}ll@{}} +\toprule +Operator & Name \\ +\midrule +\endhead +== & Equal \\ +!= & Not equal \\ +\textgreater{} & Greater than \\ +\textless{} & Less than \\ +\textgreater= & Greater than or equal to \\ +\textless= & Less than or equal to \\ +\bottomrule +\end{longtable} + +\hypertarget{logical-operators}{% +\subsubsection{Logical operators}\label{logical-operators}} + +\begin{longtable}[]{@{}ll@{}} +\toprule +Operator & Descrription \\ +\midrule +\endhead +\texttt{and} & Returns True if both statemetns are true \\ +\texttt{or} & Returns True if one of the statements is true \\ +\texttt{not} & Reerse the result, returns False if the result is true \\ +\bottomrule +\end{longtable} + +\hypertarget{identity-operators}{% +\subsubsection{Identity operators}\label{identity-operators}} + +\begin{longtable}[]{@{}ll@{}} +\toprule +Operator & Description \\ +\midrule +\endhead +is & Returns True if both variables are the same object \\ +is not & Returns True if both variables are not the same object \\ +\bottomrule +\end{longtable} + + \hypertarget{order-of-operation}{% +\subsection{Order of Operation}\label{order-of-operation}} + +Similarly to the order or precedence in mathematics, different computer +languages have their own set of rules. Here is a comprehensive table of +the order of operation that python follows. + +\begin{longtable}[]{@{} + >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.51}} + >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.49}}@{}} +\toprule +Operator & Description \\ +\midrule +\endhead +\texttt{()} & Parentheses \\ +\texttt{**} & Exponentiation \\ +\texttt{+x} \texttt{-x} \texttt{\textasciitilde{}x} & Unary plus, unary +minus, and bitwise NOT \\ +\texttt{*} \texttt{/} \texttt{//} \texttt{\%} & Multiplication, +Division, floor division, and modulus \\ +\texttt{+} \texttt{-} & Addition and subtraction \\ +\texttt{\textless{}\textless{}} \texttt{\textgreater{}\textgreater{}} & +Bitwise left and right shifts \\ +\& & Bitwise AND \\ +\^{} & Bitwise XOR \\ +\textbar{} & Bitwise OR \\ +\texttt{==} \texttt{!=} \texttt{\textgreater{}} \texttt{\textgreater{}=} +\texttt{\textless{}} \texttt{\textless{}=} \texttt{is} \texttt{is\ not} +\texttt{in} \texttt{not\ in} & Comparision, identity and membership +operators \\ +\texttt{not} & logical NOT \\ +\texttt{and} & AND \\ +\texttt{or} & OR \\ +\bottomrule +\end{longtable} + + \hypertarget{data-types}{% +\subsection{Data types}\label{data-types}} + +Data types are different ways a computer stores data. Other data types +use fewer bits than others allowing you to better utilize your computer +memory. This is important for engineers because The most common data +types that an engineer encounters in python are numeric types. - +\texttt{int} - integer - \texttt{float} - a decimal number - +\texttt{complex} - imaginary number + +The comprehensive table below show all built-in data types available in +python. + +\begin{longtable}[]{@{}ll@{}} +\toprule +Category & Data Type \\ +\midrule +\endhead +Text & int, float, complex \\ +Sequance & list, tuple, range \\ +Mapping & dict \\ +Set & set, frozenset \\ +Boolean & bytes, bytearray, memoryview \\ +Binary & bytes, bytearray, memoryview \\ +None & NoneType \\ +\bottomrule +\end{longtable} + + \hypertarget{variables}{% +\subsection{Variables}\label{variables}} + +A \textbf{variable} in Python is a name that stores a value, allowing +you to use and manipulate data efficiently. + +\hypertarget{declaring-and-assigning-variables}{% +\paragraph{Declaring and Assigning +Variables}\label{declaring-and-assigning-variables}} + +It is common in low-level computer languages to declare the datatype if +the variable. In python, the datatype is set whilst you assign it. We +assign values to variables using a single \texttt{=}. + +```python + + \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] +\prompt{In}{incolor}{1}{\boxspacing} +\begin{Verbatim}[commandchars=\\\{\}] +\PY{n}{x} \PY{o}{=} \PY{l+m+mi}{33} \PY{c+c1}{\PYZsh{} Integer} +\PY{n}{y} \PY{o}{=} \PY{l+m+mf}{3.14} \PY{c+c1}{\PYZsh{} Float} +\PY{n}{name} \PY{o}{=} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{Joe}\PY{l+s+s2}{\PYZdq{}} \PY{c+c1}{\PYZsh{} String} +\PY{n}{is\PYZus{}valid} \PY{o}{=} \PY{k+kc}{True} \PY{c+c1}{\PYZsh{} Boolean} + +\PY{n+nb}{print}\PY{p}{(}\PY{n}{x}\PY{o}{*}\PY{o}{*}\PY{l+m+mi}{2}\PY{o}{+}\PY{l+m+mi}{3}\PY{o}{*}\PY{n}{y}\PY{p}{)} +\end{Verbatim} +\end{tcolorbox} + + \begin{Verbatim}[commandchars=\\\{\}] +1098.42 + \end{Verbatim} + + Change the x and y values above, re-run the cell to see what happens. + +You can assign multiple variables at once: + +\begin{Shaded} +\begin{Highlighting}[] +\NormalTok{a, b, c }\OperatorTok{=} \DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3} +\end{Highlighting} +\end{Shaded} + +Similarly we can assign the same value to multiple variables: + +\begin{Shaded} +\begin{Highlighting}[] +\NormalTok{x }\OperatorTok{=}\NormalTok{ y }\OperatorTok{=}\NormalTok{ z }\OperatorTok{=} \DecValTok{100} +\end{Highlighting} +\end{Shaded} + + \hypertarget{rules}{% +\subparagraph{Rules}\label{rules}} + +\begin{itemize} +\tightlist +\item + Must start with a letter or \texttt{\_} +\item + Cannot start with a number +\item + Can only contain letters, numbers, and \texttt{\_} +\item + Case-sensitive (\texttt{Name} and \texttt{name} are different) +\end{itemize} + +\hypertarget{updating-variables}{% +\paragraph{Updating Variables}\label{updating-variables}} + +You can change a variable's value at any time. + +\begin{Shaded} +\begin{Highlighting}[] +\NormalTok{x }\OperatorTok{=} \DecValTok{5} +\NormalTok{x }\OperatorTok{=}\NormalTok{ x }\OperatorTok{+} \DecValTok{10} \CommentTok{\# Now x is 15} +\end{Highlighting} +\end{Shaded} + +Or shorthand: + +\begin{Shaded} +\begin{Highlighting}[] +\NormalTok{x }\OperatorTok{+=} \DecValTok{10} \CommentTok{\# Same as x = x + 10} +\end{Highlighting} +\end{Shaded} + +\hypertarget{variable-types-type-checking}{% +\paragraph{Variable Types \& Type +Checking}\label{variable-types-type-checking}} + +Use \texttt{type()} to check a variable's type. + + \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] +\prompt{In}{incolor}{2}{\boxspacing} +\begin{Verbatim}[commandchars=\\\{\}] +\PY{n}{x} \PY{o}{=} \PY{l+m+mi}{10} +\PY{n+nb}{print}\PY{p}{(}\PY{l+s+sa}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{ Variable x is type: }\PY{l+s+si}{\PYZob{}}\PY{n+nb}{type}\PY{p}{(}\PY{n}{x}\PY{p}{)}\PY{l+s+si}{\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} + +\PY{n}{y} \PY{o}{=} \PY{l+s+s2}{\PYZdq{}}\PY{l+s+s2}{Hello}\PY{l+s+s2}{\PYZdq{}} +\PY{n+nb}{print}\PY{p}{(}\PY{l+s+sa}{f}\PY{l+s+s1}{\PYZsq{}}\PY{l+s+s1}{ Variable y is type: }\PY{l+s+si}{\PYZob{}}\PY{n+nb}{type}\PY{p}{(}\PY{n}{y}\PY{p}{)}\PY{l+s+si}{\PYZcb{}}\PY{l+s+s1}{\PYZsq{}}\PY{p}{)} +\end{Verbatim} +\end{tcolorbox} + + \begin{Verbatim}[commandchars=\\\{\}] + Variable x is type: <class 'int'> + Variable y is type: <class 'str'> + \end{Verbatim} + + \hypertarget{exercise}{% +\section{Exercise}\label{exercise}} + + \begin{tcolorbox}[breakable, size=fbox, boxrule=1pt, pad at break*=1mm,colback=cellbackground, colframe=cellborder] +\prompt{In}{incolor}{ }{\boxspacing} +\begin{Verbatim}[commandchars=\\\{\}] + +\end{Verbatim} +\end{tcolorbox} + + + % Add a bibliography block to the postdoc + + + +\end{document} |
