Step-by-step Explanation:
✅ List comprehension:
This creates a list:
✅ Unpacking:
This assigns values from left to right, and reassigns variables if reused:
| Index | Value | Variable |
|---|---|---|
| 0 | 0 | m = 0 |
| 1 | 1 | n = 1 |
| 2 | 2 | m = 2 → overwrites previous m |
| 3 | 3 | n = 3 → overwrites previous n |
✅ Final output:
✅ Output:
Key concept:
-
When you repeat variable names while unpacking, the last assignment wins.
-
Earlier values are overwritten.


0 Comments:
Post a Comment