Let’s break it down step-by-step:
Code:
Step 1 – [1, 2] * 2
The * 2 duplicates the list:
So initially:
Step 2 – a[1] = 5
Index 1 refers to the second element in the list.
Original list:
We replace the 2 with 5:
Step 3 – print(a)
Output will be:
✅ Final Answer: [1, 5, 1, 2]
๐ก Key concept: Multiplying a list repeats its elements in sequence, and assignment updates just that one index.


0 Comments:
Post a Comment