88
99< meta name ="author " content ="Dr. Tobias Vlćek ">
1010
11- < title > Lecture I - Introduction – Programming with Python</ title >
11+ < title > Cheatsheet – Programming with Python</ title >
1212< style >
1313code {white-space : pre-wrap;}
1414span .smallcaps {font-variant : small-caps;}
416416 < h2 id ="toc-title "> On this page</ h2 >
417417
418418 < ul >
419- < li > < a href ="#cheatsheet " id ="toc-cheatsheet " class ="nav-link active " data-scroll-target ="#cheatsheet "> Cheatsheet</ a > </ li >
420- < li > < a href ="#lecture-i " id ="toc-lecture-i " class ="nav-link " data-scroll-target ="#lecture-i "> Lecture I</ a > </ li >
421- < li > < a href ="#cheatsheet---lecture-i " id ="toc-cheatsheet---lecture-i " class ="nav-link " data-scroll-target ="#cheatsheet---lecture-i "> Cheatsheet - Lecture I</ a >
422- < ul class ="collapse ">
423- < li > < a href ="#key-concepts " id ="toc-key-concepts " class ="nav-link " data-scroll-target ="#key-concepts "> Key Concepts</ a >
419+ < li > < a href ="#lecture-i " id ="toc-lecture-i " class ="nav-link active " data-scroll-target ="#lecture-i "> Lecture I</ a >
424420 < ul class ="collapse ">
425421 < li > < a href ="#python-basics " id ="toc-python-basics " class ="nav-link " data-scroll-target ="#python-basics "> Python Basics</ a > </ li >
426422 < li > < a href ="#variables " id ="toc-variables " class ="nav-link " data-scroll-target ="#variables "> Variables</ a > </ li >
427423 < li > < a href ="#data-types " id ="toc-data-types " class ="nav-link " data-scroll-target ="#data-types "> Data Types</ a > </ li >
428424 < li > < a href ="#basic-operators " id ="toc-basic-operators " class ="nav-link " data-scroll-target ="#basic-operators "> Basic Operators</ a > </ li >
429425 < li > < a href ="#common-functions " id ="toc-common-functions " class ="nav-link " data-scroll-target ="#common-functions "> Common Functions</ a > </ li >
430- </ ul > </ li >
431426 < li > < a href ="#best-practices " id ="toc-best-practices " class ="nav-link " data-scroll-target ="#best-practices "> Best Practices</ a > </ li >
432427 </ ul > </ li >
433428 < li > < a href ="#lecture-ii " id ="toc-lecture-ii " class ="nav-link " data-scroll-target ="#lecture-ii "> Lecture II</ a >
@@ -480,8 +475,13 @@ <h2 id="toc-title">On this page</h2>
480475 < li > < a href ="#assertions " id ="toc-assertions " class ="nav-link " data-scroll-target ="#assertions "> Assertions</ a > </ li >
481476 < li > < a href ="#debugging-tips " id ="toc-debugging-tips " class ="nav-link " data-scroll-target ="#debugging-tips "> Debugging Tips</ a > </ li >
482477 < li > < a href ="#best-practices-4 " id ="toc-best-practices-4 " class ="nav-link " data-scroll-target ="#best-practices-4 "> Best Practices</ a > </ li >
483- < li > < a href ="#common-debugging-workflow " id ="toc-common-debugging-workflow " class ="nav-link " data-scroll-target ="#common-debugging-workflow "> Common Debugging Workflow</ a >
478+ < li > < a href ="#common-debugging-workflow " id ="toc-common-debugging-workflow " class ="nav-link " data-scroll-target ="#common-debugging-workflow "> Common Debugging Workflow</ a > </ li >
479+ </ ul > </ li >
480+ < li > < a href ="#lecture-vi " id ="toc-lecture-vi " class ="nav-link " data-scroll-target ="#lecture-vi "> Lecture VI</ a >
481+ < ul class ="collapse ">
482+ < li > < a href ="#modules " id ="toc-modules " class ="nav-link " data-scroll-target ="#modules "> Modules</ a >
484483 < ul class ="collapse ">
484+ < li > < a href ="#importing-modules " id ="toc-importing-modules " class ="nav-link " data-scroll-target ="#importing-modules "> Importing Modules</ a > </ li >
485485 < li > < a href ="#common-built-in-modules " id ="toc-common-built-in-modules " class ="nav-link " data-scroll-target ="#common-built-in-modules "> Common Built-in Modules</ a > </ li >
486486 </ ul > </ li >
487487 < li > < a href ="#random-module " id ="toc-random-module " class ="nav-link " data-scroll-target ="#random-module "> Random Module</ a > </ li >
@@ -490,9 +490,8 @@ <h2 id="toc-title">On this page</h2>
490490 < li > < a href ="#regular-expressions-re " id ="toc-regular-expressions-re " class ="nav-link " data-scroll-target ="#regular-expressions-re "> Regular Expressions (re)</ a > </ li >
491491 < li > < a href ="#package-management " id ="toc-package-management " class ="nav-link " data-scroll-target ="#package-management "> Package Management</ a > </ li >
492492 < li > < a href ="#best-practices-5 " id ="toc-best-practices-5 " class ="nav-link " data-scroll-target ="#best-practices-5 "> Best Practices</ a > </ li >
493- < li > < a href ="#common-errors " id ="toc-common-errors " class ="nav-link " data-scroll-target ="#common-errors "> Common Errors</ a > </ li >
494493 </ ul > </ li >
495- < li > < a href ="#cheatsheet--- lecture-vii " id ="toc-cheatsheet--- lecture-vii " class ="nav-link " data-scroll-target ="#cheatsheet--- lecture-vii "> Cheatsheet - Lecture VII</ a >
494+ < li > < a href ="#lecture-vii " id ="toc-lecture-vii " class ="nav-link " data-scroll-target ="#lecture-vii "> Lecture VII</ a >
496495 < ul class ="collapse ">
497496 < li > < a href ="#numpy-basics " id ="toc-numpy-basics " class ="nav-link " data-scroll-target ="#numpy-basics "> NumPy Basics</ a >
498497 < ul class ="collapse ">
@@ -522,28 +521,21 @@ <h2 id="toc-title">On this page</h2>
522521
523522< header id ="title-block-header " class ="quarto-title-block default ">
524523< div class ="quarto-title ">
525- < h1 class ="title "> Lecture I - Introduction </ h1 >
524+ < h1 class ="title "> Cheatsheet </ h1 >
526525< p class ="subtitle lead "> Programming with Python</ p >
527526</ div >
528527
529528
530- < div class ="quarto-title-meta-author ">
531- < div class ="quarto-title-meta-heading "> Author</ div >
532- < div class ="quarto-title-meta-heading "> Affiliation</ div >
533-
534- < div class ="quarto-title-meta-contents ">
535- < p class ="author "> Dr. Tobias Vlćek </ p >
536- </ div >
537- < div class ="quarto-title-meta-contents ">
538- < p class ="affiliation ">
539- Kühne Logistics University Hamburg - Fall 2024
540- </ p >
541- </ div >
542- </ div >
543529
544530< div class ="quarto-title-meta ">
545531
546-
532+ < div >
533+ < div class ="quarto-title-meta-heading "> Author</ div >
534+ < div class ="quarto-title-meta-contents ">
535+ < p > Dr. Tobias Vlćek </ p >
536+ </ div >
537+ </ div >
538+
547539
548540
549541 </ div >
@@ -553,35 +545,27 @@ <h1 class="title">Lecture I - Introduction</h1>
553545</ header >
554546
555547
556- < section id ="cheatsheet " class ="level1 ">
557- < h1 > Cheatsheet</ h1 >
558- </ section >
559548< section id ="lecture-i " class ="level1 ">
560549< h1 > Lecture I</ h1 >
561- </ section >
562- < section id ="cheatsheet---lecture-i " class ="level1 ">
563- < h1 > Cheatsheet - Lecture I</ h1 >
564- < section id ="key-concepts " class ="level2 ">
565- < h2 class ="anchored " data-anchor-id ="key-concepts "> Key Concepts</ h2 >
566- < section id ="python-basics " class ="level3 ">
567- < h3 class ="anchored " data-anchor-id ="python-basics "> Python Basics</ h3 >
550+ < section id ="python-basics " class ="level2 ">
551+ < h2 class ="anchored " data-anchor-id ="python-basics "> Python Basics</ h2 >
568552< ul >
569553< li > Python is an < strong > interpreted language</ strong > - code is executed line by line</ li >
570554< li > Comments start with < code > #</ code > </ li >
571555< li > Code blocks are defined by indentation</ li >
572556</ ul >
573557</ section >
574- < section id ="variables " class ="level3 ">
575- < h3 class ="anchored " data-anchor-id ="variables "> Variables</ h3 >
558+ < section id ="variables " class ="level2 ">
559+ < h2 class ="anchored " data-anchor-id ="variables "> Variables</ h2 >
576560< ul >
577561< li > Created using assignment operator < code > =</ code > </ li >
578562< li > Must start with letter or underscore</ li >
579563< li > Case sensitive</ li >
580564< li > Cannot use reserved words</ li >
581565</ ul >
582566</ section >
583- < section id ="data-types " class ="level3 ">
584- < h3 class ="anchored " data-anchor-id ="data-types "> Data Types</ h3 >
567+ < section id ="data-types " class ="level2 ">
568+ < h2 class ="anchored " data-anchor-id ="data-types "> Data Types</ h2 >
585569< ol type ="1 ">
586570< li > < strong > Strings (str)</ strong >
587571< ul >
@@ -600,8 +584,8 @@ <h3 class="anchored" data-anchor-id="data-types">Data Types</h3>
600584</ ul > </ li >
601585</ ol >
602586</ section >
603- < section id ="basic-operators " class ="level3 ">
604- < h3 class ="anchored " data-anchor-id ="basic-operators "> Basic Operators</ h3 >
587+ < section id ="basic-operators " class ="level2 ">
588+ < h2 class ="anchored " data-anchor-id ="basic-operators "> Basic Operators</ h2 >
605589< div class ="sourceCode " id ="cb1 "> < pre class ="sourceCode python code-with-copy "> < code class ="sourceCode python "> < span id ="cb1-1 "> < a href ="#cb1-1 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="co "> # Arithmetic</ span > </ span >
606590< span id ="cb1-2 "> < a href ="#cb1-2 " aria-hidden ="true " tabindex ="-1 "> </ a > addition < span class ="op "> =</ span > < span class ="dv "> 1</ span > < span class ="op "> +</ span > < span class ="dv "> 2</ span > < span class ="co "> # 3</ span > </ span >
607591< span id ="cb1-3 "> < a href ="#cb1-3 " aria-hidden ="true " tabindex ="-1 "> </ a > subtraction < span class ="op "> =</ span > < span class ="dv "> 1</ span > < span class ="op "> -</ span > < span class ="dv "> 2</ span > < span class ="co "> # -1</ span > </ span >
@@ -611,8 +595,8 @@ <h3 class="anchored" data-anchor-id="basic-operators">Basic Operators</h3>
611595< span id ="cb1-7 "> < a href ="#cb1-7 " aria-hidden ="true " tabindex ="-1 "> </ a > exponentiation < span class ="op "> =</ span > < span class ="dv "> 9</ span > < span class ="op "> **</ span > < span class ="fl "> 0.5</ span > < span class ="co "> # 3.0</ span > </ span >
612596< span id ="cb1-8 "> < a href ="#cb1-8 " aria-hidden ="true " tabindex ="-1 "> </ a > modulo < span class ="op "> =</ span > < span class ="dv "> 10</ span > < span class ="op "> %</ span > < span class ="dv "> 3</ span > < span class ="co "> # 1</ span > </ span > </ code > < button title ="Copy to Clipboard " class ="code-copy-button "> < i class ="bi "> </ i > </ button > </ pre > </ div >
613597</ section >
614- < section id ="common-functions " class ="level3 ">
615- < h3 class ="anchored " data-anchor-id ="common-functions "> Common Functions</ h3 >
598+ < section id ="common-functions " class ="level2 ">
599+ < h2 class ="anchored " data-anchor-id ="common-functions "> Common Functions</ h2 >
616600< div class ="sourceCode " id ="cb2 "> < pre class ="sourceCode python code-with-copy "> < code class ="sourceCode python "> < span id ="cb2-1 "> < a href ="#cb2-1 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="co "> # Input/Output</ span > </ span >
617601< span id ="cb2-2 "> < a href ="#cb2-2 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="bu "> print</ span > (< span class ="st "> "Hello"</ span > ) < span class ="co "> # Display output</ span > </ span >
618602< span id ="cb2-3 "> < a href ="#cb2-3 " aria-hidden ="true " tabindex ="-1 "> </ a > name < span class ="op "> =</ span > < span class ="bu "> input</ span > (< span class ="st "> "Enter name: "</ span > ) < span class ="co "> # Get user input</ span > </ span >
@@ -627,7 +611,6 @@ <h3 class="anchored" data-anchor-id="common-functions">Common Functions</h3>
627611< span id ="cb2-12 "> < a href ="#cb2-12 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="bu "> len</ span > (< span class ="st "> "Hello"</ span > ) < span class ="co "> # Get length</ span > </ span >
628612< span id ="cb2-13 "> < a href ="#cb2-13 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="bu "> type</ span > (variable) < span class ="co "> # Get type of variable</ span > </ span > </ code > < button title ="Copy to Clipboard " class ="code-copy-button "> < i class ="bi "> </ i > </ button > </ pre > </ div >
629613</ section >
630- </ section >
631614< section id ="best-practices " class ="level2 ">
632615< h2 class ="anchored " data-anchor-id ="best-practices "> Best Practices</ h2 >
633616< ol type ="1 ">
@@ -737,6 +720,7 @@ <h2 class="anchored" data-anchor-id="best-practices-1">Best Practices</h2>
737720< li > Avoid infinite loops</ li >
738721< li > Keep code blocks focused and manageable</ li >
739722</ ol >
723+ < hr >
740724</ section >
741725</ section >
742726< section id ="lecture-iii " class ="level1 ">
@@ -860,6 +844,7 @@ <h2 class="anchored" data-anchor-id="best-practices-2">Best Practices</h2>
860844< li > variable_name (snake_case)</ li >
861845</ ul > </ li >
862846</ ol >
847+ < hr >
863848</ section >
864849</ section >
865850< section id ="lecture-iv " class ="level1 ">
@@ -977,6 +962,7 @@ <h2 class="anchored" data-anchor-id="best-practices-3">Best Practices</h2>
977962< li > Always use < code > with</ code > statement for file operations</ li >
978963< li > Close files after use if not using < code > with</ code > </ li >
979964</ ol >
965+ < hr >
980966</ section >
981967</ section >
982968< section id ="lecture-v " class ="level1 ">
@@ -1087,24 +1073,27 @@ <h2 class="anchored" data-anchor-id="common-debugging-workflow">Common Debugging
10871073< li > Test the fix</ li >
10881074< li > Add error handling if needed</ li >
10891075</ ol >
1090- < pre > < code >
1091- # Cheatsheet - Lecture VI
1092-
1093- ## Modules
1094-
1095- ### Importing Modules
1096- ```python
1097- # Basic import
1098- import module_name
1099- module_name.function_name()
1100-
1101- # Import specific items
1102- from module_name import function_name, another_function
1103- function_name()
1104-
1105- # Import with alias
1106- import module_name as alias
1107- alias.function_name()</ code > </ pre >
1076+ < hr >
1077+ </ section >
1078+ </ section >
1079+ < section id ="lecture-vi " class ="level1 ">
1080+ < h1 > Lecture VI</ h1 >
1081+ < section id ="modules " class ="level2 ">
1082+ < h2 class ="anchored " data-anchor-id ="modules "> Modules</ h2 >
1083+ < section id ="importing-modules " class ="level3 ">
1084+ < h3 class ="anchored " data-anchor-id ="importing-modules "> Importing Modules</ h3 >
1085+ < div class ="sourceCode " id ="cb27 "> < pre class ="sourceCode python code-with-copy "> < code class ="sourceCode python "> < span id ="cb27-1 "> < a href ="#cb27-1 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="co "> # Basic import</ span > </ span >
1086+ < span id ="cb27-2 "> < a href ="#cb27-2 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="im "> import</ span > module_name</ span >
1087+ < span id ="cb27-3 "> < a href ="#cb27-3 " aria-hidden ="true " tabindex ="-1 "> </ a > module_name.function_name()</ span >
1088+ < span id ="cb27-4 "> < a href ="#cb27-4 " aria-hidden ="true " tabindex ="-1 "> </ a > </ span >
1089+ < span id ="cb27-5 "> < a href ="#cb27-5 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="co "> # Import specific items</ span > </ span >
1090+ < span id ="cb27-6 "> < a href ="#cb27-6 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="im "> from</ span > module_name < span class ="im "> import</ span > function_name, another_function</ span >
1091+ < span id ="cb27-7 "> < a href ="#cb27-7 " aria-hidden ="true " tabindex ="-1 "> </ a > function_name()</ span >
1092+ < span id ="cb27-8 "> < a href ="#cb27-8 " aria-hidden ="true " tabindex ="-1 "> </ a > </ span >
1093+ < span id ="cb27-9 "> < a href ="#cb27-9 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="co "> # Import with alias</ span > </ span >
1094+ < span id ="cb27-10 "> < a href ="#cb27-10 " aria-hidden ="true " tabindex ="-1 "> </ a > < span class ="im "> import</ span > module_name < span class ="im "> as</ span > alias</ span >
1095+ < span id ="cb27-11 "> < a href ="#cb27-11 " aria-hidden ="true " tabindex ="-1 "> </ a > alias.function_name()</ span > </ code > < button title ="Copy to Clipboard " class ="code-copy-button "> < i class ="bi "> </ i > </ button > </ pre > </ div >
1096+ </ section >
11081097< section id ="common-built-in-modules " class ="level3 ">
11091098< h3 class ="anchored " data-anchor-id ="common-built-in-modules "> Common Built-in Modules</ h3 >
11101099< table class ="caption-top table ">
@@ -1234,20 +1223,11 @@ <h2 class="anchored" data-anchor-id="best-practices-5">Best Practices</h2>
12341223< li > Document package dependencies</ li >
12351224< li > Use regular expressions carefully and test them thoroughly</ li >
12361225</ ol >
1237- </ section >
1238- < section id ="common-errors " class ="level2 ">
1239- < h2 class ="anchored " data-anchor-id ="common-errors "> Common Errors</ h2 >
1240- < ul >
1241- < li > < strong > ImportError</ strong > : Module not found</ li >
1242- < li > < strong > ModuleNotFoundError</ strong > : Package not installed</ li >
1243- < li > < strong > AttributeError</ strong > : Module attribute not found</ li >
1244- < li > < strong > re.error</ strong > : Invalid regular expression pattern</ li >
1245- < li > < strong > PermissionError</ strong > : File access denied</ li >
1246- </ ul >
1226+ < hr >
12471227</ section >
12481228</ section >
1249- < section id ="cheatsheet--- lecture-vii " class ="level1 ">
1250- < h1 > Cheatsheet - Lecture VII</ h1 >
1229+ < section id ="lecture-vii " class ="level1 ">
1230+ < h1 > Lecture VII</ h1 >
12511231< section id ="numpy-basics " class ="level2 ">
12521232< h2 class ="anchored " data-anchor-id ="numpy-basics "> NumPy Basics</ h2 >
12531233< section id ="creating-arrays " class ="level3 ">
0 commit comments