-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocument.tex
More file actions
823 lines (598 loc) · 27.5 KB
/
document.tex
File metadata and controls
823 lines (598 loc) · 27.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
\documentclass[a4paper,11pt]{article}
% ───────────────────────────
% PACKAGES
% ───────────────────────────
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\usepackage{graphicx}
\usepackage{amsmath, amssymb}
\usepackage{booktabs}
\usepackage{enumitem}
\usepackage{hyperref}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{fancyhdr}
\usepackage{titlesec}
\usepackage{parskip}
\usepackage{minted}
\usepackage{inconsolata} % clean monospaced font
\usepackage{mathpazo} % professional text font
\usepackage{array}
\usepackage{booktabs}
\usepackage[table]{xcolor}
% ───────────────────────────
% GEOMETRY
% ───────────────────────────
\geometry{
a4paper,
left=2.5cm,
right=2.5cm,
top=2.5cm,
bottom=2.5cm
}
% ───────────────────────────
% HEADER/FOOTER
% ───────────────────────────
\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
\lhead{\textsf{\textcolor{gray}{Python Notes}}}
\rhead{\textsf{\textcolor{gray}{Siddharth Patel}}}
\rfoot{\textsf{\textcolor{gray}{\thepage}}}
% ───────────────────────────
% TITLE FORMAT
% ───────────────────────────
\titleformat{\section}
{\Large\bfseries\sffamily\color{black}}
{\thesection}{1em}{}
\titleformat{\subsection}
{\large\bfseries\sffamily\color{black}}
{\thesubsection}{1em}{}
% ───────────────────────────
% MINTED SETTINGS
% ───────────────────────────
\definecolor{mintbg}{rgb}{0.97,0.97,0.97}
\setminted{
bgcolor=mintbg,
fontsize=\footnotesize,
linenos=true,
numbersep=5pt,
frame=lines,
framesep=2mm,
breaklines=true,
tabsize=4,
encoding=utf8
}
% ───────────────────────────
% TITLE PAGE
% ───────────────────────────
\title{\Huge \textbf{My Python Course Notes}\\[1ex]
\Large Structured Revision for Every Lesson}
\author{\textbf{Siddharth Patel} \\ HTW Berlin}
\date{\today}
% ───────────────────────────
% BEGIN DOCUMENT
% ───────────────────────────
\begin{document}
\maketitle
\thispagestyle{empty}
\newpage
\tableofcontents
\newpage
% ───────────────────────────
% FIRST LESSON
% ───────────────────────────
\section{Print Function – Full Usage Guide}
\inputminted{python}{Python_Files/print_guid.py}
\vspace{1em}
\subsection*{Additional Functions Used in This Lesson}
\vspace{1em}
\subsection*{Referenced Functions – Syntax and Output Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{7.5cm} p{3cm}}
\toprule
Function & Syntax & Return / Output Type \\
\midrule
\texttt{with open()} & \texttt{with open("file.txt", "w") as f:} & File object \\
\texttt{print(..., file=f)} & \texttt{print("text", file=f)} & Writes to file, returns \texttt{None} \\
\texttt{range()} & \texttt{range(3)} or \texttt{range(start, stop, step)} & Range object (iterable) \\
\texttt{time.sleep()} & \texttt{time.sleep(seconds)} & None (pauses execution) \\
\bottomrule
\end{tabular}
\newpage
\section{Input Function – Full Usage Guide}
\inputminted{python}{Python_Files/input_guid.py}
\vspace{1em}
\subsection*{Referenced Functions – Syntax and Output Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{8cm} p{3cm}}
\toprule
Function / Statement & Syntax & Return / Output Type \\
\midrule
\texttt{.split()} & \texttt{string.split()} or \texttt{string.split("delimiter")} & List of strings \\
\texttt{map()} & \texttt{map(function, iterable)} & Map object (can be converted to list) \\
\texttt{list()} & \texttt{list(iterable)} & List object \\
\texttt{try / except} &
\texttt{try:\newline \hspace{1em} code\newline except ErrorType:\newline \hspace{1em} fallback} & Flow control – no return value; handles runtime errors \\
\bottomrule
\end{tabular}
\newpage
\section{Math Operators – Full Usage Guide}
\inputminted{python}{Python_Files/math_operators_guid.py}
\newpage
\section{Strings – Full Usage Guide}
\inputminted{python}{Python_Files/string_guid.py}
\vspace{1em}
\subsection*{Referenced Methods – Syntax and Output Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{8cm} p{3cm}}
\toprule
Method / Function & Syntax & Return / Output Type \\
\midrule
\texttt{.capitalize()} & \texttt{str.capitalize()} & \texttt{str} \\
\texttt{.lower()} & \texttt{str.lower()} & \texttt{str} \\
\texttt{.title()} & \texttt{str.title()} & \texttt{str} \\
\texttt{.casefold()} & \texttt{str.casefold()} & \texttt{str} \\
\texttt{.upper()} & \texttt{str.upper()} & \texttt{str} \\
\texttt{.count()} & \texttt{str.count(substring, start, end)} & \texttt{int} \\
\texttt{.find()} & \texttt{str.find(substring, start, end)} & \texttt{int} \\
\texttt{.replace()} & \texttt{str.replace(old, new, count)} & \texttt{str} \\
\texttt{.swapcase()} & \texttt{str.swapcase()} & \texttt{str} \\
\texttt{.join()} & \texttt{"separator".join(iterable)} & \texttt{str} \\
\bottomrule
\end{tabular}
\newpage
\section{If, Else, and Conditional Operators}
\inputminted{python}{Python_Files/if_else_guid.py}
\vspace{1em}
\subsection*{Referenced Operators – Syntax and Output Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{7.5cm} p{3cm}}
\toprule
Operator & Syntax & Return / Output Type \\
\midrule
\texttt{==} (Equal) & \texttt{x == y} & \texttt{bool} \\
\texttt{!=} (Not Equal) & \texttt{x != y} & \texttt{bool} \\
\texttt{<} (Less Than) & \texttt{x < y} & \texttt{bool} \\
\texttt{<=} (Less Than or Equal) & \texttt{x <= y} & \texttt{bool} \\
\texttt{>} (Greater Than) & \texttt{x > y} & \texttt{bool} \\
\texttt{>=} (Greater Than or Equal) & \texttt{x >= y} & \texttt{bool} \\
\texttt{and} (Logical AND) & \texttt{x > 5 and x < 10} & \texttt{bool} \\
\texttt{or} (Logical OR) & \texttt{x < 5 or x > 10} & \texttt{bool} \\
\texttt{not} (Logical NOT) & \texttt{not (x > 5)} & \texttt{bool} \\
\textit{Ternary Expression} & \texttt{value1 if condition else value2} & Result of \texttt{value1} or \texttt{value2} \\
\bottomrule
\end{tabular}
\newpage
\section{While Loop – Full Usage Guide}
\inputminted{python}{Python_Files/while_loop_guid.py}
\vspace{1em}
\subsection*{Referenced Keywords and Operators – Syntax and Output Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{7.5cm} p{3cm}}
\toprule
Keyword / Operator & Syntax & Return / Effect \\
\midrule
\texttt{while} & \texttt{while condition:} & Repeats block while condition is \texttt{True} \\
\texttt{break} & \texttt{break} & Immediately exits the nearest enclosing loop \\
\texttt{continue} & \texttt{continue} & Skips current iteration and continues with the next \\
\texttt{+=} & \texttt{x += y} & Updates: \texttt{x = x + y} \\
\texttt{-=} & \texttt{x -= y} & Updates: \texttt{x = x - y} \\
\texttt{*=} & \texttt{x *= y} & Updates: \texttt{x = x * y} \\
\texttt{/=} & \texttt{x /= y} & Updates: \texttt{x = x / y} \\
\texttt{++} / \texttt{--} & Not supported in Python & Causes \texttt{SyntaxError} \\
\bottomrule
\end{tabular}
\newpage
\section{For Loop – Full Usage Guide}
\inputminted{python}{Python_Files/for_loop_guid.py}
\vspace{1em}
\subsection*{Referenced Iteration Helpers – Syntax and Output Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{7.5cm} p{3cm}}
\toprule
Function / Method & Syntax & Return / Output Type \\
\midrule
\texttt{tuple} & \texttt{(a, b, c)} & Iterable (ordered, immutable) \\
\texttt{set} & \texttt{\{a, b, c\}} & Iterable (unordered, unique) \\
\texttt{dict.items()} & \texttt{dict.items()} & Iterable of \texttt{(key, value)} pairs \\
\texttt{enumerate()} & \texttt{enumerate(iterable)} & Iterable of \texttt{(index, item)} tuples \\
\bottomrule
\end{tabular}
\newpage
\section{Functions – Full Usage Guide}
\inputminted{python}{Python_Files/functions_guid.py}
\newpage
\section{Lists – Introduction}
\inputminted{python}{Python_Files/list_intro_guid.py}
\vspace{1em}
\subsection*{List Types and Creation Methods}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4.2cm} p{7cm} p{2.8cm}}
\toprule
List Type & Syntax / Example & Notes \\
\midrule
Homogeneous List & \texttt{[1, 2, 3, 4]} & All elements of the same type \\
String List & \texttt{["apple", "banana"]} & List of strings \\
Mixed-Type List & \texttt{["hi", 42, 3.14, True]} & Supports multiple data types \\
Empty List & \texttt{[]} & No elements yet \\
Nested List & \texttt{[[1, 2], [3, 4]]} & List inside a list \\
From String & \texttt{list("abc")} & Converts string into list of characters \\
From Range & \texttt{list(range(5))} & Converts range object into list \\
\bottomrule
\end{tabular}
\newpage
\section{List Methods – General Usage}
\inputminted{python}{Python_Files/list_methods_general.py}
\vspace{1em}
\subsection*{Common List Methods – Overview Table}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{6cm} p{3.5cm}}
\toprule
Method & Description & Return Value \\
\midrule
\texttt{append(x)} & Add element \texttt{x} to the end & \texttt{None} \\
\texttt{insert(i,x)} & Insert \texttt{x} at index \texttt{i} & \texttt{None} \\
\texttt{remove(x)} & Remove first occurrence of \texttt{x} & \texttt{None} \\
\texttt{pop(i)} & Remove and return item at index \texttt{i} (last by default) & Element \\
\texttt{clear()} & Remove all items from the list & \texttt{None} \\
\texttt{copy()} & Return a shallow copy of the list & List copy \\
\texttt{extend(iter)}& Append elements from iterable & \texttt{None} \\
\texttt{index(x)} & Return first index of \texttt{x} (error if not found) & Integer \\
\texttt{count(x)} & Count occurrences of \texttt{x} & Integer \\
\texttt{reverse()} & Reverse items in-place & \texttt{None} \\
\texttt{sort()} & Sort the list in-place & \texttt{None} \\
\bottomrule
\end{tabular}
\newpage
\section{List Methods – Numeric Lists Only}
\inputminted{python}{Python_Files/list_methods_numeric.py}
\vspace{1em}
\subsection*{List Methods for Numbers – Reference Table}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{6cm} p{3.5cm}}
\toprule
Method & Description & Return Value \\
\midrule
\texttt{sort()} & Sort list in ascending order (in-place) & \texttt{None} \\
\texttt{reverse()} & Reverse the list (in-place) & \texttt{None} \\
\texttt{count(x)} & Count how many times \texttt{x} appears & Integer \\
\texttt{max(lst)} & Return maximum element & Element \\
\texttt{min(lst)} & Return minimum element & Element \\
\texttt{sum(lst)} & Sum of all list items & Numeric \\
\texttt{sorted(lst)} & Return a new sorted list & New list \\
\texttt{avg = sum()/len()} & Compute average (manual) & Float \\
\bottomrule
\end{tabular}
\newpage
\section{2D Lists and Nested Loops}
\inputminted{python}{Python_Files/nested_list_guid.py}
\newpage
\section{Tuples – Full Usage Guide}
\inputminted{python}{Python_Files/tuples_guid.py}
\vspace{1em}
\subsection*{Tuple Functions – Syntax and Return Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{7cm} p{3cm}}
\toprule
Function & Syntax & Return Type \\
\midrule
\texttt{len()} & \texttt{len(tuple)} & \texttt{int} (length of tuple) \\
\texttt{max()} & \texttt{max(tuple)} & Largest item from tuple \\
\texttt{min()} & \texttt{min(tuple)} & Smallest item from tuple \\
\texttt{tuple()} & \texttt{tuple(iterable)} & A new tuple object \\
\bottomrule
\end{tabular}
\newpage
\section{Sets – General Usage Guide}
\inputminted{python}{Python_Files/sets_guid_general.py}
\vspace{1em}
\subsection*{General Set Methods – Syntax and Return Type}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{7cm} p{3cm}}
\toprule
Method & Description & Return Type \\
\midrule
\texttt{add(x)} & Adds element \texttt{x} to the set & \texttt{None} \\
\texttt{remove(x)} & Removes \texttt{x}; error if not found & \texttt{None} \\
\texttt{discard(x)} & Removes \texttt{x}; no error if not found & \texttt{None} \\
\texttt{pop()} & Removes and returns an arbitrary element & Element \\
\texttt{clear()} & Removes all items from the set & \texttt{None} \\
\texttt{copy()} & Returns a shallow copy of the set & Set copy \\
\texttt{update(iter)} & Adds elements from another iterable & \texttt{None} \\
\bottomrule
\end{tabular}
\newpage
\section{Sets – Mathematical Operations}
\inputminted{python}{Python_Files/sets_math_guid.py}
\vspace{1em}
\subsection*{Set Operations – Syntax and Result}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{6.5cm} p{3cm}}
\toprule
Method / Operator & Description & Return Type \\
\midrule
\texttt{a.union(b)} / \texttt{a | b} & All unique elements from both sets & New set \\
\texttt{a.update(b)} & Adds all elements from b to a & \texttt{None} (in-place) \\
\texttt{a.intersection(b)} / \texttt{a \& b} & Elements common to both sets & New set \\
\texttt{a.intersection\_update(b)} & Keeps only common elements in a & \texttt{None} (in-place) \\
\texttt{a.difference(b)} / \texttt{a - b} & Elements in a but not in b & New set \\
\texttt{a.difference\_update(b)} & Removes items in b from a & \texttt{None} (in-place) \\
\texttt{a.symmetric\_difference(b)} / \texttt{a \textasciicircum{} b} & Elements in a or b, not both & New set \\
\texttt{a.symmetric\_difference\_update(b)} & Updates a to symmetric diff & \texttt{None} (in-place) \\
\bottomrule
\end{tabular}
\vspace{1em}
\subsection*{Set Comparison – Membership and Relationship}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4.5cm} p{7.2cm} p{2cm}}
\toprule
Method & Description & Returns \\
\midrule
\texttt{a.issubset(b)} & True if all elements of a are in b & Boolean \\
\texttt{a.issuperset(b)} & True if a contains all elements of b & Boolean \\
\texttt{a.isdisjoint(b)} & True if a and b have no elements in common & Boolean \\
\bottomrule
\end{tabular}
\vspace{1em}
\subsection*{Set Operations – Visual Explanation}
\renewcommand{\arraystretch}{1.8}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.2cm} >{\centering\arraybackslash}p{3.5cm} p{6cm} >{\centering\arraybackslash}p{2.5cm}}
\toprule
Set Operation & Diagram & Explanation & \ttfamily In Python \\
\midrule
Union &
\vspace{0.4em}\includegraphics[width=2.8cm]{images/1.png} &
$A \cup B$ is the set of all elements that are a member of $A$, or $B$, or both. &
union() \\
Intersection &
\vspace{0.4em}\includegraphics[width=2.8cm]{images/2.png} &
$A \cap B$ is the set of all elements that are a member of both $A$ and $B$. &
intersection() \\
Difference &
\vspace{0.4em}\includegraphics[width=2.8cm]{images/3.png} &
$A \setminus B$ is the set of all elements of $A$ that are not in $B$. &
difference() \\
Symmetric Difference &
\vspace{0.4em}\includegraphics[width=2.8cm]{images/4.png} &
$A \Delta B$ is the set of elements in either $A$ or $B$, but not both. &
\shortstack{\\symmetric\\\_difference()} \\
\bottomrule
\end{tabular}
\newpage
\section{Dictionary}
\inputminted{python}{Python_Files/dict_basics_guid.py}
\newpage
\section{Dictionary – Most Important Methods}
\inputminted{python}{Python_Files/dict_methods_guid.py}
\inputminted{python}{Python_Files/dict_key_value_item_get_examples.py}
\vspace{1em}
\subsection*{Common Dictionary Methods – Reference Table}
\rowcolors{2}{gray!10}{white}
\renewcommand{\arraystretch}{1.6}
\begin{tabular}{>{\bfseries}p{4cm} p{6.5cm} p{2.8cm}}
\toprule
Method & Description & Return Type \\
\midrule
\texttt{get(key, default)} & Returns value if key exists, else default or None & Value or None \\
\texttt{keys()} & Returns all keys in the dictionary & dict\_keys view \\
\texttt{values()} & Returns all values in the dictionary & dict\_values view \\
\texttt{items()} & Returns key-value pairs as tuples & dict\_items view \\
\texttt{pop(key)} & Removes and returns value for given key & Value \\
\texttt{popitem()} & Removes and returns the last key-value pair & (key, value) tuple \\
\texttt{update(dict)} & Updates dict with another dict or key-value pairs & None \\
\texttt{clear()} & Removes all items from the dictionary & None \\
\texttt{copy()} & Returns a shallow copy of the dictionary & New dict \\
\bottomrule
\end{tabular}
\newpage
\section{Comprehensions – List Comprehensions}
\inputminted{python}{Python_Files/comprehensions_list_guid.py}
\vspace{1em}
\subsection*{List Comprehension Syntax Breakdown}
\renewcommand{\arraystretch}{1.6}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.8cm} p{9.2cm}}
\toprule
Component & Description \\
\midrule
\texttt{expression} & The result expression evaluated and added to the list. Can be a variable or formula. \\
\texttt{item} & The looping variable assigned in each iteration. \\
\texttt{iterable} & An iterable like \texttt{range()}, list, tuple, or string. \\
\texttt{condition} (optional) & A filter. Only items satisfying this condition are included. \\
\bottomrule
\end{tabular}
\newpage
\section{Comprehensions – Tuple Comprehensions}
\inputminted{python}{Python_Files/comprehensions_tuple_guid.py}
\vspace{1em}
\subsection*{Tuple Comprehensions – Syntax Overview}
\renewcommand{\arraystretch}{1.6}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.8cm} p{9.2cm}}
\toprule
Component & Description \\
\midrule
\texttt{tuple()} wrapper & Required to convert the generator into a tuple. \\
\texttt{(expression for item in iterable)} & Generator-style expression inside \texttt{tuple()}. \\
\texttt{expression} & Defines what value to include. \\
\texttt{condition} (optional) & Filters the items added to the final tuple. \\
\bottomrule
\end{tabular}
\newpage
\section{Comprehensions – Dictionary and Set}
\inputminted{python}{Python_Files/comprehensions_dict_set_guid.py}
\vspace{1em}
\subsection*{Comprehension Syntax Comparison Table}
\renewcommand{\arraystretch}{1.6}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.5cm} p{8.5cm}}
\toprule
Comprehension Type & Syntax Example \\
\midrule
List & \texttt{[x for x in iterable if condition]} \\
Tuple & \texttt{tuple(x for x in iterable if condition)} \\
Dictionary & \texttt{\{k: v for (k, v) in iterable if condition\}} \\
Set & \texttt{\{x for x in iterable if condition\}} \\
\bottomrule
\end{tabular}
\newpage
\section{Classes and Objects}
\inputminted{python}{Python_Files/class_intro_guid.py}
\vspace{1em}
\subsection*{Overview – Class Terminology}
\renewcommand{\arraystretch}{1.6}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{3.8cm} p{9.2cm}}
\toprule
Concept & Explanation \\
\midrule
\texttt{class} & A blueprint or template for creating objects \\
\texttt{object} & An instance of a class with its own data (attributes) \\
\texttt{self} & Refers to the current object instance (used inside methods) \\
\texttt{\_\_init\_\_()} & The constructor method, automatically called when creating an object \\
Attribute & A variable attached to an object (e.g., \texttt{self.name}) \\
Method & A function defined inside a class (e.g., \texttt{deposit()}) \\
Instance & A specific object created from a class (e.g., \texttt{account1}) \\
\bottomrule
\end{tabular}
\newpage
\section{Objects – Using Class Instances}
\inputminted{python}{Python_Files/object_usage_guid.py}
\vspace{1em}
\subsection*{Object Usage vs. \texttt{self} in Classes}
\renewcommand{\arraystretch}{1.6}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{5cm} p{8cm}}
\toprule
Context & Syntax / Explanation \\
\midrule
Outside the Class & \texttt{account1.balance}, \texttt{account2.deposit(100)} \\
Inside the Class & \texttt{self.balance}, \texttt{self.deposit(...)} \\
Why? & \texttt{self} refers to the object on which the method was called \\
Example & \texttt{account1.withdraw(500)} → \texttt{self = account1} inside the method \\
\bottomrule
\end{tabular}
\newpage
\section{Private Attributes, Getter and \texttt{\_\_str\_\_} Method}
\inputminted{python}{Python_Files/private_attribute_guid.py}
\vspace{1em}
\subsection*{Private Attributes and Access Methods}
\renewcommand{\arraystretch}{1.4}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4.5cm} p{8.5cm}}
\toprule
Access Type & Description \\
\midrule
\texttt{self.\_\_attribute} & Private attributes within the class. Only accessible inside the class. \\
\texttt{obj.getAttribute()} & Getter method for safe external access. \\
\texttt{obj.\_\_attribute} & Direct access from outside is not allowed (causes error or unexpected behavior). \\
\texttt{print(obj)} & Automatically calls the \texttt{\_\_str\_\_()} method, which returns formatted info. \\
\bottomrule
\end{tabular}
\newpage
\section{Inheritance – Extending Classes with \texttt{super()}}
\inputminted{python}{Python_Files/inheritance_guid.py}
\vspace{1em}
\subsection*{Inheritance – Overview}
\renewcommand{\arraystretch}{1.4}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4.5cm} p{9cm}}
\toprule
Term & Explanation \\
\midrule
\texttt{class Subclass(BaseClass):} & Creates a derived class that inherits from the base class. \\
\texttt{super().\_\_init\_\_()} & Calls the constructor of the base class. \\
\texttt{self.deposit(...)} & Calls a method from the base class. \\
\texttt{self.\_\_attribute} & Private attribute of the base class – accessible only via methods. \\
\texttt{add\_interest()} & New method of the subclass to calculate and add interest. \\
\bottomrule
\end{tabular}
\newpage
\section{File Access in Python}
\inputminted{python}{Python_Files/file_access_guid.py}
\vspace{1em}
\subsection*{File Access – Modes and Methods Overview}
\renewcommand{\arraystretch}{1.5}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{9cm}}
\toprule
Concept / Function & Description \\
\midrule
\texttt{open('file.txt', 'r')} & Open text file for reading \\
\texttt{open('file.txt', 'w')} & Open text file for writing (overwrites content) \\
\texttt{open(..., encoding='utf-8')} & Open file with specific character encoding \\
\texttt{file.read()} & Read entire file content as a string \\
\texttt{file.readlines()} & Read all lines into a list \\
\texttt{file.readline()} & Read one line at a time \\
\texttt{for line in file} & Loop through file line by line \\
\texttt{file.write(...)} & Write a string to file (no auto line break) \\
\texttt{with open(...) as f} & Automatically closes file after block \\
\texttt{file.close()} & Manually closes file (not needed with \texttt{with}) \\
\texttt{open(..., 'rb')} & Open binary file for reading \\
\texttt{open(..., 'wb')} & Open binary file for writing \\
\texttt{bytes([0,1,2])} & Convert list to byte array for binary write \\
\bottomrule
\end{tabular}
\newpage
\inputminted{python}{Python_Files/file_modes_explained.py}
\vspace{1em}
\subsection*{File Access Modes – Overview}
\renewcommand{\arraystretch}{1.4}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{2.2cm} p{5cm} p{3.3cm} >{\ttfamily}p{3.5cm}}
\toprule
Mode & Description & Use Case & Example Code \\
\midrule
\texttt{'r'} & Read (text) – file must exist & Reading config or data files & open('file.txt', 'r') \\
\texttt{'w'} & Write (text) – overwrite or create & Writing logs or reports & open('log.txt', 'w') \\
\texttt{'a'} & Append (text) – add to end, create if needed & Appending logs or results & open('log.txt', 'a') \\
\texttt{'x'} & Exclusive write – fail if file exists & Safe one-time file creation & open('unique.txt', 'x') \\
\texttt{'rb'} & Read binary – file must exist & Reading image or binary data & open('image.png', 'rb') \\
\texttt{'wb'} & Write binary – overwrite or create & Saving structured bytes or images & open('output.bin', 'wb') \\
\texttt{'ab'} & Append binary – add to end, create if needed & Streaming sensor or audio bytes & open('audio.raw', 'ab') \\
\texttt{'xb'} & Exclusive binary write – fail if file exists & Writing protected firmware or assets & open('firmware.bin', 'xb') \\
\bottomrule
\end{tabular}
\newpage
\section{Exceptions in Python}
\inputminted{python}{Python_Files/exceptions_guid.py}
\vspace{1em}
\subsection*{Common Python Exception Types}
\renewcommand{\arraystretch}{1.5}
\rowcolors{2}{gray!10}{white}
\begin{tabular}{>{\bfseries}p{4cm} p{10cm}}
\toprule
Exception Type & Description \\
\midrule
\texttt{Exception} & Base class for all built-in exceptions. \\
\texttt{ArithmeticError} & Base class for numeric calculation errors. \\
\texttt{ZeroDivisionError} & Raised when division or modulo by zero takes place. \\
\texttt{OverflowError} & Raised when a calculation exceeds the limits for a numeric type. \\
\texttt{FloatingPointError} & Raised when a floating-point calculation fails. \\
\texttt{AssertionError} & Raised when an assert statement fails. \\
\texttt{AttributeError} & Raised when an invalid attribute reference occurs. \\
\texttt{EOFError} & Raised when \texttt{input()} hits an end-of-file condition. \\
\texttt{ImportError} & Raised when an import fails. \\
\texttt{ModuleNotFoundError} & Raised when a module cannot be found. \\
\texttt{IndexError} & Raised when a sequence subscript is out of range. \\
\texttt{KeyError} & Raised when a dictionary key isn’t found. \\
\texttt{NameError} & Raised when a variable is not found. \\
\texttt{UnboundLocalError} & Raised when a local variable is referenced before assignment. \\
\texttt{MemoryError} & Raised when an operation runs out of memory. \\
\texttt{OSError} & Raised for system-related errors. \\
\texttt{FileNotFoundError} & Raised when a file or directory is requested but doesn’t exist. \\
\texttt{PermissionError} & Raised when trying to perform an operation without proper access rights. \\
\texttt{TimeoutError} & Raised when a system function times out. \\
\texttt{TypeError} & Raised when an operation or function is applied to the wrong type. \\
\texttt{ValueError} & Raised when an operation receives an argument of correct type but improper value. \\
\texttt{UnicodeError} & Raised when encoding or decoding Unicode fails. \\
\texttt{IndentationError} & Raised when there is incorrect indentation. \\
\texttt{SyntaxError} & Raised when Python code is syntactically incorrect. \\
\texttt{RuntimeError} & Raised when an error is detected that doesn’t fall in other categories. \\
\bottomrule
\end{tabular}
\end{document}