Let’s break it step by step ๐
a = [0] * 4[0] is a list with a single element → [0].
* 4 repeats it 4 times.
-
So, a = [0, 0, 0, 0].
a[2] = 7
-
In Python, list indexing starts at 0.
a[0] → 0, a[1] → 0, a[2] → 0, a[3] → 0.
-
The code sets the 3rd element (index 2) to 7.
-
Now a = [0, 0, 7, 0].
print(a)
-
This prints the final list:
✅ Output: [0, 0, 7, 0]


0 Comments:
Post a Comment