Python Control Flow
Conditionals & Loops
Master decision-making and iteration in Python — the foundation of all programming logic.
Python 3
✓ Core Concepts
2 Topics
01
Control Flow & Operators
| Category | Operators | Example |
|---|---|---|
| Arithmetic | + - * / // % ** | 10 % 3 = 1, 2**3 = 8 |
| Comparison | == != > < >= <= | Always return True/False |
| Logical | and or not | age > 18 and age < 60 |
| Assignment | += -= *= //= | x += 5 → x = x + 5 |
| Membership | in not in | 2 in [1,2,3] → True |
02
Loops in Python
Python — Loops
for i in range(1, 10, 2): # 1 3 5 7 9 print(i) # break — exit loop; continue — skip iteration for i in range(5): if i == 2: continue print(i) # 0 1 3 4 # DSA Example: find maximum nums = [3, 7, 2, 9, 5] max_val = nums[0] for x in nums: if x > max_val: max_val = x print(max_val) # 9
while loops are used when you don't know the number of iterations in advance. for loops iterate over sequences.
✓
Quick Quiz
1. break vs continue — which skips rest of current iteration only?
2. List comprehension: squares of 0..3?
3. Walrus operator := assigns and returns in…
4. elif is short for…
5. range(3) produces…