Code Explanation:
๐น Step 1: Variable Initialization
a = 0
b = 5
a = 0 → False in boolean context
b = 5 → True in boolean context
๐น Step 2: for Loop Starts
for i in range(3):
range(3) → values of i are 0, 1, 2
๐น Step 3: First Iteration (i = 0)
▶ Line: a = a or b
0 or 5
or returns the first truthy value
Result → 5
✅ a = 5
▶ Line: b = b and i
5 and 0
and returns the first falsy value
Result → 0
✅ b = 0
๐น Step 4: Second Iteration (i = 1)
▶ Line: a = a or b
5 or 0
First truthy value → 5
✅ a remains 5
▶ Line: b = b and i
0 and 1
First falsy value → 0
✅ b remains 0
๐น Step 5: Third Iteration (i = 2)
▶ Line: a = a or b
5 or 0 → 5
▶ Line: b = b and i
0 and 2 → 0
๐น Step 6: Final Output
print(a, b)
✅ Output
5 0
.png)

0 Comments:
Post a Comment