Repository navigation
Expand file tree
/
Copy pathPython Full Course.html
More file actions
2385 lines (1953 loc) · 98.3 KB
/
Copy pathPython Full Course.html
File metadata and controls
2385 lines (1953 loc) · 98.3 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
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Python Full Course 2026 - Complete Guide PDF</title>
<style>
/* PDF-optimized styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', 'Helvetica', sans-serif;
line-height: 1.5;
color: #000;
background: white;
padding: 0.5in;
max-width: 100%;
}
.container {
max-width: 100%;
margin: 0 auto;
}
/* Header styles */
.header {
text-align: center;
margin-bottom: 30px;
padding-bottom: 20px;
border-bottom: 3px solid #306998; /* Python blue */
}
.header h1 {
font-size: 32pt;
color: #306998;
margin-bottom: 10px;
}
.header h2 {
font-size: 18pt;
color: #FFD43B; /* Python yellow */
background: #306998;
display: inline-block;
padding: 8px 20px;
border-radius: 30px;
margin-top: 10px;
}
.header p {
font-size: 14pt;
color: #333;
margin-top: 15px;
}
/* Section styles */
.section {
margin: 40px 0 20px 0;
page-break-after: avoid;
}
.section-title {
font-size: 24pt;
font-weight: bold;
color: #306998;
margin: 30px 0 20px 0;
padding-bottom: 8px;
border-bottom: 3px solid #FFD43B;
background: #f0f8ff;
padding: 10px 15px;
}
/* Topic styles */
.topic {
margin: 30px 0;
page-break-inside: avoid;
}
.topic-header {
margin-bottom: 15px;
background: #e6f3ff;
padding: 12px 15px;
border-left: 5px solid #306998;
}
.topic-number {
font-weight: bold;
font-size: 14pt;
color: #306998;
margin-right: 15px;
}
.topic-title {
font-size: 20pt;
font-weight: bold;
color: #1a1a1a;
}
/* Content boxes */
.question-box {
margin: 20px 0;
padding: 20px;
border-left: 4px solid #FFD43B;
background: #f9f9f9;
}
.question {
font-size: 16pt;
font-weight: bold;
color: #306998;
margin-bottom: 15px;
}
.answer {
margin-bottom: 15px;
font-size: 12pt;
}
/* Code blocks */
.code-block {
background: #2b2b2b;
color: #f8f8f2;
border: 1px solid #444;
padding: 20px;
margin: 15px 0;
font-family: 'Courier New', monospace;
font-size: 11pt;
white-space: pre-wrap;
page-break-inside: avoid;
border-radius: 5px;
}
.code-block pre {
margin: 0;
white-space: pre-wrap;
color: #f8f8f2;
}
/* Comments in code */
.comment {
color: #6a9955;
font-style: italic;
}
/* Python-specific syntax highlighting */
.keyword {
color: #569cd6;
font-weight: bold;
}
.string {
color: #ce9178;
}
.function {
color: #dcdcaa;
}
.number {
color: #b5cea8;
}
/* Step boxes */
.step-box {
margin: 20px 0;
padding: 20px;
border: 1px solid #306998;
background: #fff;
border-radius: 8px;
}
.step-box h4 {
font-size: 15pt;
color: #306998;
margin-bottom: 15px;
border-bottom: 2px solid #FFD43B;
padding-bottom: 8px;
}
.step {
margin-bottom: 12px;
padding-left: 20px;
border-left: 3px solid #FFD43B;
}
.step strong {
color: #306998;
}
/* Tables */
.table-container {
margin: 20px 0;
page-break-inside: avoid;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
border: 2px solid #306998;
}
th {
background: #306998;
color: white;
font-weight: bold;
padding: 12px;
text-align: left;
border: 1px solid #FFD43B;
}
td {
padding: 10px 12px;
border: 1px solid #306998;
}
tr:nth-child(even) {
background: #f2f8ff;
}
/* Key points */
.key-points {
margin: 15px 0;
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.key-point {
background: #306998;
color: white;
padding: 6px 16px;
border-radius: 20px;
font-size: 11pt;
font-weight: bold;
}
/* Notes and tips */
.note-box, .tip-box, .warning-box {
padding: 18px;
margin: 20px 0;
border-left: 6px solid;
page-break-inside: avoid;
border-radius: 0 8px 8px 0;
}
.note-box {
background: #e7f3ff;
border-left-color: #2196F3;
}
.tip-box {
background: #e8f5e9;
border-left-color: #4CAF50;
}
.warning-box {
background: #fff3e0;
border-left-color: #FF9800;
}
/* Footer */
.footer {
margin-top: 60px;
padding: 30px;
text-align: center;
border-top: 3px solid #306998;
background: #f0f8ff;
font-size: 11pt;
page-break-after: avoid;
}
/* Print-specific styles */
@media print {
body {
padding: 0.25in;
}
.section {
page-break-after: avoid;
}
.topic {
page-break-inside: avoid;
}
.code-block {
page-break-inside: avoid;
background: #f0f0f0;
color: #000;
border: 1px solid #000;
}
.comment {
color: #006400;
}
.keyword {
color: #0000ff;
}
.string {
color: #a31515;
}
.key-point, th {
background: #306998 !important;
color: white !important;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
}
}
/* Page breaks */
.page-break {
page-break-before: always;
}
/* Python logo style */
.python-logo {
font-size: 40px;
margin: 10px 0;
}
/* Quick reference cards */
.ref-card {
border: 2px solid #306998;
border-radius: 8px;
padding: 15px;
margin: 15px 0;
background: #fafafa;
}
.ref-card h3 {
color: #306998;
border-bottom: 2px solid #FFD43B;
padding-bottom: 8px;
margin-bottom: 12px;
}
/* Floating buttons */
.floating-buttons {
position: fixed;
bottom: 30px;
right: 30px;
display: flex;
flex-direction: column;
gap: 15px;
z-index: 1000;
}
.btn {
width: 60px;
height: 60px;
border-radius: 50%;
background: #306998;
color: white;
border: none;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
transition: all 0.3s ease;
}
.btn:hover {
transform: scale(1.1);
background: #3c82ba;
}
.btn-print {
background: #FFD43B;
color: #306998;
}
.btn-print:hover {
background: #ffe066;
}
@media print {
.floating-buttons {
display: none;
}
body {
padding: 0;
}
}
</style>
</head>
<body>
<div class="floating-buttons">
<button class="btn btn-print" onclick="window.print()" title="Print / Save as PDF">🖨️</button>
<button class="btn btn-top" onclick="window.scrollTo({top: 0, behavior: 'smooth'})" title="Scroll to Top">⬆️</button>
</div>
<div class="container">
<!-- Cover Page -->
<div class="header">
<div class="python-logo">🐍</div>
<h1>Python Full Course 2026</h1>
<h2>Complete Guide with Step-by-Step Explanations</h2>
<p>Beginner to Advanced • 25 Topics • Project-Based Learning</p>
<p style="margin-top: 30px; font-size: 12pt;">📚 Based on popular YouTube curriculum • Updated for 2026</p>
<p style="margin-top: 40px; font-size: 11pt;">PDF Version 1.0 • Complete Python Programming Guide</p>
</div>
<!-- Table of Contents -->
<div class="section">
<h2 class="section-title">📑 Table of Contents</h2>
<div style="columns: 2; margin: 20px 0; line-height: 2;">
<p><strong>Section 1:</strong> Python Basics (Topics 1-6)</p>
<p><strong>Section 2:</strong> Control Flow (Topics 7-9)</p>
<p><strong>Section 3:</strong> Data Structures (Topics 10-13)</p>
<p><strong>Section 4:</strong> Functions (Topics 14-16)</p>
<p><strong>Section 5:</strong> OOP (Topics 17-19)</p>
<p><strong>Section 6:</strong> Advanced Topics (Topics 20-22)</p>
<p><strong>Section 7:</strong> File Handling (Topics 23-24)</p>
<p><strong>Section 8:</strong> Projects (Topic 25)</p>
</div>
</div>
<!-- Section 1: Python Basics -->
<div class="section page-break">
<h2 class="section-title">📘 Section 1: Python Basics</h2>
<!-- Topic 1: What is Python? -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 01</span>
<span class="topic-title">What is Python?</span>
</div>
<div class="question-box">
<div class="question">Q: What is Python and why is it so popular?</div>
<div class="answer">
<p><strong>A:</strong> Python is a high-level, interpreted programming language known for its simplicity and readability. Created by Guido van Rossum and released in 1991.</p>
</div>
<div class="step-box">
<h4>Step-by-Step Explanation:</h4>
<div class="step">
<strong>Step 1: Key Features</strong>
<ul>
<li><strong>Simple syntax:</strong> Reads like English, easy to learn</li>
<li><strong>Interpreted:</strong> No compilation needed</li>
<li><strong>Dynamically typed:</strong> No variable type declarations</li>
<li><strong>Object-oriented:</strong> Supports classes and objects</li>
<li><strong>Large standard library:</strong> "Batteries included"</li>
</ul>
</div>
<div class="step">
<strong>Step 2: Popular Applications</strong>
<ul>
<li>Web Development (Django, Flask)</li>
<li>Data Science & Machine Learning</li>
<li>Artificial Intelligence</li>
<li>Automation & Scripting</li>
<li>Scientific Computing</li>
<li>Game Development</li>
<li>Desktop Applications</li>
</ul>
</div>
<div class="step">
<strong>Step 3: Why Python in 2026?</strong>
<ul>
<li>Most popular language for AI/ML</li>
<li>Huge community support</li>
<li>Extensive libraries and frameworks</li>
<li>High demand in job market</li>
<li>Beginner-friendly but powerful</li>
</ul>
</div>
</div>
<div class="code-block">
<pre><span class="comment"># Your first Python program</span>
print(<span class="string">"Hello, World!"</span>) <span class="comment"># This prints to console</span>
<span class="comment"># Python is easy to read</span>
name = <span class="string">"Alice"</span> <span class="comment"># No type declaration needed</span>
age = 25 <span class="comment"># Python infers the type</span>
print(<span class="string">f"My name is {name} and I'm {age} years old"</span>)</pre>
</div>
<div class="note-box">
<strong>📝 Fun Fact:</strong> Python was named after "Monty Python's Flying Circus," not the snake!
</div>
<div class="key-points">
<span class="key-point">Simple syntax</span>
<span class="key-point">Interpreted</span>
<span class="key-point">Dynamically typed</span>
<span class="key-point">Batteries included</span>
</div>
</div>
</div>
<!-- Topic 2: Installing Python and Setup -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 02</span>
<span class="topic-title">Installing Python and Setup</span>
</div>
<div class="question-box">
<div class="question">Q: How do I install Python and set up my development environment?</div>
<div class="step-box">
<h4>Step-by-Step Installation Guide:</h4>
<div class="step">
<strong>Step 1: Download Python</strong>
<p>Go to <strong>python.org</strong> and download the latest version (Python 3.12+ recommended for 2026).</p>
</div>
<div class="step">
<strong>Step 2: Install Python</strong>
<p>Run the installer. <strong>IMPORTANT:</strong> Check "Add Python to PATH" during installation.</p>
</div>
<div class="step">
<strong>Step 3: Verify Installation</strong>
<p>Open terminal/command prompt and type: <code>python --version</code></p>
</div>
<div class="step">
<strong>Step 4: Choose an Editor</strong>
<ul>
<li><strong>VS Code:</strong> Most popular, great extensions</li>
<li><strong>PyCharm:</strong> Full-featured Python IDE</li>
<li><strong>IDLE:</strong> Comes with Python, good for beginners</li>
<li><strong>Jupyter Notebook:</strong> Great for data science</li>
</ul>
</div>
</div>
<div class="code-block">
<pre><span class="comment"># Check Python version in code</span>
import sys
print(<span class="string">f"Python version: {sys.version}"</span>)
<span class="comment"># Check if Python is working</span>
print(<span class="string">"Python is successfully installed!"</span>)</pre>
</div>
<div class="tip-box">
<strong>💡 Pro Tip:</strong> Use virtual environments for different projects:
<pre>python -m venv myenv
source myenv/bin/activate # On Mac/Linux
myenv\Scripts\activate # On Windows</pre>
</div>
</div>
</div>
<!-- Topic 3: Python Syntax and Variables -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 03</span>
<span class="topic-title">Python Syntax and Variables</span>
</div>
<div class="question-box">
<div class="question">Q: What are the basic syntax rules and how do variables work in Python?</div>
<div class="code-block">
<pre><span class="comment"># Python Syntax Rules</span>
<span class="comment"># 1. No semicolons needed (but optional)</span>
print(<span class="string">"Hello"</span>) <span class="comment"># Correct</span>
print(<span class="string">"Hello"</span>); <span class="comment"># Also correct but not Pythonic</span>
<span class="comment"># 2. Indentation matters! (usually 4 spaces)</span>
if True:
print(<span class="string">"Indented properly"</span>) <span class="comment"># This belongs to the if</span>
print(<span class="string">"Not indented"</span>) <span class="comment"># This is outside the if</span>
<span class="comment"># 3. Case-sensitive</span>
name = <span class="string">"John"</span>
Name = <span class="string">"Jane"</span> <span class="comment"># Different variable</span>
<span class="comment"># ===== VARIABLES =====</span>
<span class="comment"># Variable assignment (no type declaration needed)</span>
x = 5 <span class="comment"># Integer</span>
y = 3.14 <span class="comment"># Float</span>
name = <span class="string">"Python"</span> <span class="comment"># String</span>
is_fun = True <span class="comment"># Boolean</span>
nothing = None <span class="comment"># NoneType (null)</span>
<span class="comment"># Multiple assignment</span>
a, b, c = 1, 2, 3 <span class="comment"># a=1, b=2, c=3</span>
x = y = z = 0 <span class="comment"># All set to 0</span>
<span class="comment"># Variable naming rules</span>
valid_name = <span class="string">"OK"</span> <span class="comment"># Snake_case recommended</span>
validName = <span class="string">"Also OK"</span> <span class="comment"># camelCase works too</span>
_private = <span class="string">"Convention"</span> <span class="comment"># _ prefix for "private"</span>
<span class="comment"># 2invalid = "No" # Can't start with number</span>
<span class="comment"># class = "No" # Can't use keywords</span>
<span class="comment"># Type checking</span>
print(type(x)) <span class="comment"># <class 'int'></span>
print(type(name)) <span class="comment"># <class 'str'></span>
<span class="comment"># Dynamic typing (can change type)</span>
var = 10 <span class="comment"># var is int</span>
var = <span class="string">"now string"</span> <span class="comment"># var is now str (allowed)</span></pre>
</div>
<div class="table-container">
<table>
<tr><th>Naming Convention</th><th>Example</th><th>Usage</th></tr>
<tr><td>snake_case</td><td>user_name</td><td>Variables, functions (recommended)</td></tr>
<tr><td>PascalCase</td><td>ClassName</td><td>Classes</td></tr>
<tr><td>UPPER_CASE</td><td>MAX_SIZE</td><td>Constants</td></tr>
<tr><td>_private</td><td>_internal</td><td>"Private" by convention</td></tr>
</table>
</div>
</div>
</div>
<!-- Topic 4: Data Types -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 04</span>
<span class="topic-title">Python Data Types</span>
</div>
<div class="question-box">
<div class="question">Q: What are the built-in data types in Python?</div>
<div class="code-block">
<pre><span class="comment"># ===== NUMERIC TYPES =====</span>
<span class="comment"># int - integers</span>
age = 25
large_number = 1_000_000 <span class="comment"># Underscores for readability</span>
<span class="comment"># float - floating point numbers</span>
price = 19.99
scientific = 1.5e-3 <span class="comment"># 0.0015</span>
<span class="comment"># complex - complex numbers</span>
complex_num = 3 + 4j
<span class="comment"># ===== SEQUENCE TYPES =====</span>
<span class="comment"># str - strings</span>
name = <span class="string">"Python"</span>
multiline = <span class="string">"""This is a
multi-line string"""</span>
<span class="comment"># list - mutable, ordered</span>
fruits = [<span class="string">"apple"</span>, <span class="string">"banana"</span>, <span class="string">"orange"</span>]
mixed = [1, <span class="string">"hello"</span>, 3.14, True]
<span class="comment"># tuple - immutable, ordered</span>
coordinates = (10, 20)
single_item = (<span class="number">1</span>,) <span class="comment"># Comma needed</span>
<span class="comment"># range - sequence of numbers</span>
numbers = range(5) <span class="comment"># 0,1,2,3,4</span>
<span class="comment"># ===== MAPPING TYPE =====</span>
<span class="comment"># dict - key-value pairs</span>
person = {
<span class="string">"name"</span>: <span class="string">"John"</span>,
<span class="string">"age"</span>: 30,
<span class="string">"city"</span>: <span class="string">"New York"</span>
}
<span class="comment"># ===== SET TYPES =====</span>
<span class="comment"># set - unordered, unique items</span>
unique_numbers = {1, 2, 3, 3, 2} <span class="comment"># {1,2,3}</span>
<span class="comment"># frozenset - immutable set</span>
frozen = frozenset([1, 2, 3])
<span class="comment"># ===== BOOLEAN TYPE =====</span>
is_valid = True
is_done = False
<span class="comment"># ===== NONE TYPE =====</span>
result = None <span class="comment"># Represents absence of value</span>
<span class="comment"># Type conversion</span>
int(<span class="string">"123"</span>) <span class="comment"># 123 (string to int)</span>
str(456) <span class="comment"># "456" (int to string)</span>
float(<span class="string">"3.14"</span>) <span class="comment"># 3.14</span>
list((1,2,3)) <span class="comment"># [1,2,3] (tuple to list)</span></pre>
</div>
</div>
</div>
<!-- Topic 5: Operators -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 05</span>
<span class="topic-title">Python Operators</span>
</div>
<div class="code-block">
<pre><span class="comment"># ===== ARITHMETIC OPERATORS =====</span>
a, b = 10, 3
print(a + b) <span class="comment"># 13 (addition)</span>
print(a - b) <span class="comment"># 7 (subtraction)</span>
print(a * b) <span class="comment"># 30 (multiplication)</span>
print(a / b) <span class="comment"># 3.333... (division - always returns float)</span>
print(a // b) <span class="comment"># 3 (floor division)</span>
print(a % b) <span class="comment"># 1 (modulo/remainder)</span>
print(a ** b) <span class="comment"># 1000 (exponentiation)</span>
<span class="comment"># ===== COMPARISON OPERATORS =====</span>
print(a == b) <span class="comment"># False (equal)</span>
print(a != b) <span class="comment"># True (not equal)</span>
print(a > b) <span class="comment"># True (greater than)</span>
print(a < b) <span class="comment"># False (less than)</span>
print(a >= b) <span class="comment"># True (greater than or equal)</span>
print(a <= b) <span class="comment"># False (less than or equal)</span>
<span class="comment"># ===== LOGICAL OPERATORS =====</span>
x, y = True, False
print(x and y) <span class="comment"># False (both must be True)</span>
print(x or y) <span class="comment"># True (at least one True)</span>
print(not x) <span class="comment"># False (inverts)</span>
<span class="comment"># ===== ASSIGNMENT OPERATORS =====</span>
c = 5
c += 3 <span class="comment"># c = c + 3 (now 8)</span>
c -= 2 <span class="comment"># c = c - 2 (now 6)</span>
c *= 4 <span class="comment"># c = c * 4 (now 24)</span>
c /= 3 <span class="comment"># c = c / 3 (now 8.0)</span>
c //= 2 <span class="comment"># c = c // 2 (now 4.0)</span>
c %= 3 <span class="comment"># c = c % 3 (now 1.0)</span>
c **= 2 <span class="comment"># c = c ** 2 (now 1.0)</span>
<span class="comment"># ===== IDENTITY OPERATORS =====</span>
x = [1,2,3]
y = [1,2,3]
z = x
print(x is z) <span class="comment"># True (same object)</span>
print(x is y) <span class="comment"># False (different objects)</span>
print(x is not y) <span class="comment"># True</span>
print(x == y) <span class="comment"># True (same value)</span>
<span class="comment"># ===== MEMBERSHIP OPERATORS =====</span>
fruits = [<span class="string">"apple"</span>, <span class="string">"banana"</span>, <span class="string">"orange"</span>]
print(<span class="string">"apple"</span> in fruits) <span class="comment"># True</span>
print(<span class="string">"grape"</span> not in fruits) <span class="comment"># True</span>
<span class="comment"># ===== BITWISE OPERATORS =====</span>
m, n = 5, 3 <span class="comment"># 5=101, 3=011 in binary</span>
print(m & n) <span class="comment"># 1 (AND: 101 & 011 = 001)</span>
print(m | n) <span class="comment"># 7 (OR: 101 | 011 = 111)</span>
print(m ^ n) <span class="comment"># 6 (XOR: 101 ^ 011 = 110)</span>
print(~m) <span class="comment"># -6 (NOT: inverts bits)</span>
print(m << 1) <span class="comment"># 10 (left shift: 1010)</span>
print(m >> 1) <span class="comment"># 2 (right shift: 10)</span></pre>
</div>
</div>
<!-- Topic 6: Input and Output -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 06</span>
<span class="topic-title">Input and Output</span>
</div>
<div class="code-block">
<pre><span class="comment"># ===== PRINTING OUTPUT =====</span>
print(<span class="string">"Hello World"</span>) <span class="comment"># Basic printing</span>
print(<span class="string">"Hello"</span>, <span class="string">"World"</span>, sep=<span class="string">", "</span>) <span class="comment"># Separator: "Hello, World"</span>
print(<span class="string">"Hello"</span>, end=<span class="string">"!!!\n"</span>) <span class="comment"># Custom ending</span>
<span class="comment"># Formatted strings (f-strings) - Python 3.6+</span>
name = <span class="string">"Alice"</span>
age = 25
print(<span class="string">f"My name is {name} and I'm {age} years old"</span>)
print(<span class="string">f"In 5 years, I'll be {age + 5}"</span>) <span class="comment"># Expressions work</span>
<span class="comment"># .format() method</span>
print(<span class="string">"My name is {} and I'm {}"</span>.<span class="function">format</span>(name, age))
<span class="comment"># % formatting (old style)</span>
print(<span class="string">"My name is %s and I'm %d"</span> % (name, age))
<span class="comment"># ===== GETTING INPUT =====</span>
<span class="comment"># input() always returns a string</span>
name = <span class="built_in">input</span>(<span class="string">"Enter your name: "</span>)
print(<span class="string">f"Hello, {name}!"</span>)
<span class="comment"># Convert input to numbers</span>
age = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"Enter your age: "</span>))
height = <span class="built_in">float</span>(<span class="built_in">input</span>(<span class="string">"Enter your height: "</span>))
<span class="comment"># Multiple inputs</span>
x, y = <span class="built_in">input</span>(<span class="string">"Enter two numbers: "</span>).<span class="function">split</span>()
x, y = <span class="built_in">int</span>(x), <span class="built_in">int</span>(y)
<span class="comment"># ===== PRACTICAL EXAMPLE =====</span>
name = <span class="built_in">input</span>(<span class="string">"What's your name? "</span>)
age = <span class="built_in">int</span>(<span class="built_in">input</span>(<span class="string">"How old are you? "</span>))
city = <span class="built_in">input</span>(<span class="string">"Where do you live? "</span>)
print(<span class="string">f"""
--- USER PROFILE ---
Name: {name}
Age: {age}
City: {city}
Born in: {2026 - age}
"""</span>)</pre>
</div>
</div>
</div>
<!-- Section 2: Control Flow -->
<div class="section page-break">
<h2 class="section-title">🔄 Section 2: Control Flow</h2>
<!-- Topic 7: Conditional Statements -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 07</span>
<span class="topic-title">Conditional Statements (if-elif-else)</span>
</div>
<div class="code-block">
<pre><span class="comment"># ===== IF STATEMENT =====</span>
age = 18
if age >= 18:
print(<span class="string">"You are an adult"</span>)
<span class="comment"># ===== IF-ELSE =====</span>
temperature = 25
if temperature > 30:
print(<span class="string">"It's hot!"</span>)
else:
print(<span class="string">"It's not too hot"</span>)
<span class="comment"># ===== IF-ELIF-ELSE LADDER =====</span>
score = 85
if score >= 90:
grade = <span class="string">"A"</span>
elif score >= 80:
grade = <span class="string">"B"</span>
elif score >= 70:
grade = <span class="string">"C"</span>
elif score >= 60:
grade = <span class="string">"D"</span>
else:
grade = <span class="string">"F"</span>
print(<span class="string">f"Grade: {grade}"</span>) <span class="comment"># Grade: B</span>
<span class="comment"># ===== NESTED CONDITIONS =====</span>
has_license = True
has_car = False
if has_license:
if has_car:
print(<span class="string">"You can drive"</span>)
else:
print(<span class="string">"You need a car"</span>)
else:
print(<span class="string">"You need a license"</span>)
<span class="comment"># ===== MULTIPLE CONDITIONS =====</span>
age = 25
has_ticket = True
if age >= 18 and has_ticket:
print(<span class="string">"You can enter"</span>)
if age < 12 or age > 60:
print(<span class="string">"You get a discount"</span>)
<span class="comment"># ===== TERNARY OPERATOR (conditional expression)</span>
age = 20
status = <span class="string">"Adult"</span> if age >= 18 else <span class="string">"Minor"</span>
print(status) <span class="comment"># "Adult"</span>
<span class="comment"># ===== TRUTHY AND FALSY VALUES =====</span>
<span class="comment"># Falsy: None, False, 0, 0.0, "" (empty string), [], (), {}</span>
<span class="comment"># Everything else is Truthy</span>
name = <span class="string">""</span>
if name: <span class="comment"># Empty string is falsy</span>
print(<span class="string">f"Hello, {name}"</span>)
else:
print(<span class="string">"Hello, Guest"</span>) <span class="comment"># This runs</span>
<span class="comment"># ===== MATCH CASE (Python 3.10+) =====</span>
<span class="comment"># Similar to switch in other languages</span>
command = <span class="string">"start"</span>
match command:
case <span class="string">"start"</span>:
print(<span class="string">"Starting..."</span>)
case <span class="string">"stop"</span>:
print(<span class="string">"Stopping..."</span>)
case <span class="string">"pause"</span>:
print(<span class="string">"Pausing..."</span>)
case _: <span class="comment"># Default case</span>
print(<span class="string">"Unknown command"</span>)</pre>
</div>
</div>
<!-- Topic 8: Loops -->
<div class="topic">
<div class="topic-header">
<span class="topic-number">Topic 08</span>
<span class="topic-title">Loops (for and while)</span>
</div>
<div class="code-block">
<pre><span class="comment"># ===== FOR LOOP =====</span>
<span class="comment"># Looping through a range</span>
for i in range(5): <span class="comment"># 0,1,2,3,4</span>
print(i)
for i in range(2, 6): <span class="comment"># 2,3,4,5</span>
print(i)
for i in range(1, 10, 2): <span class="comment"># 1,3,5,7,9 (step 2)</span>
print(i)
<span class="comment"># Looping through sequences</span>
fruits = [<span class="string">"apple"</span>, <span class="string">"banana"</span>, <span class="string">"orange"</span>]
for fruit in fruits:
print(fruit)
<span class="comment"># Looping through string</span>
for char in <span class="string">"Python"</span>:
print(char)
<span class="comment"># Looping with index (enumerate)</span>
for index, fruit in enumerate(fruits):
print(<span class="string">f"{index}: {fruit}"</span>)
<span class="comment"># Looping through dictionary</span>
person = {<span class="string">"name"</span>: <span class="string">"John"</span>, <span class="string">"age"</span>: 30, <span class="string">"city"</span>: <span class="string">"NYC"</span>}
for key in person:
print(<span class="string">f"{key}: {person[key]}"</span>)
for key, value in person.items():
print(<span class="string">f"{key}: {value}"</span>)
<span class="comment"># ===== WHILE LOOP =====</span>
count = 0
while count < 5:
print(count)
count += 1
<span class="comment"># While with user input</span>
secret = 7
guess = 0
while guess != secret:
guess = int(input(<span class="string">"Guess the number (1-10): "</span>))
if guess < secret:
print(<span class="string">"Too low"</span>)
elif guess > secret:
print(<span class="string">"Too high"</span>)
print(<span class="string">"Correct!"</span>)
<span class="comment"># ===== LOOP CONTROL =====</span>
<span class="comment"># break - exit loop</span>
for i in range(10):
if i == 5:
break
print(i) <span class="comment"># 0,1,2,3,4</span>
<span class="comment"># continue - skip to next iteration</span>
for i in range(5):
if i == 2:
continue
print(i) <span class="comment"># 0,1,3,4</span>
<span class="comment"># else clause in loops (runs if no break)</span>