Explanation:
๐ข 1. Create the List
x = [1, 2, 3]
A list is created with three elements:
Index: 0 1 2
↓ ↓ ↓
x = [ 1, 2, 3 ]
๐ก 2. x.pop(1)
x.pop(1)
pop(1) removes and returns the element at index 1.
Index 1 contains:
2
So:
x.pop(1) → 2
At the same time, the list changes:
Before: [1, 2, 3]
↑
removed
After: [1, 3]
๐ต 3. x[-1]
Now Python evaluates:
x[-1]
Important: this happens after pop(1) has modified the list.
The list is now:
[1, 3]
-1 means the last element.
Therefore:
x[-1] → 3
๐ 4. Addition
The expression becomes:
2 + 3
Therefore:
5
๐ด 5. print()
Finally:
print(5)
✅ Final Output
5

0 Comments:
Post a Comment