Step 1: Create the lista = [1, 2]
The list has 2 elements:
[1, 2]Step 2: a.append(a) (Tricky part )
a.append(a)append() adds one single element to the list.
-
Here, that element is the list itself (a).
So the list becomes self-referential:
[1, 2, [...]]([...] means the list contains a reference to itself)
Step 3: Length of the list
print(len(a))-
Elements are:
-
1
- 2
the list a itself
So:
len(a) = 3
✅ Final Output
3Key Concept (Very Important)
append() adds one object, not multiple elements
-
Python stores a reference, not a copy
-
Self-referencing lists are allowed in Python
Interview Tip


0 Comments:
Post a Comment