Explanation:
๐น 1. List Initialization
lst = [1, 2, 3]
A list named lst is created.
It contains three elements: 1, 2, 3.
๐ After this line:
lst = [1, 2, 3]
๐น 2. Using extend() Method
lst.extend([4, 5])
The extend() method adds elements of another list to the existing list.
It modifies the original list in-place (does NOT create a new list).
๐ After this operation:
lst = [1, 2, 3, 4, 5]
๐น 3. Return Value of extend()
Important point:
extend() returns None
It does NOT return the updated list
๐น 4. Print Statement
print(lst.extend([4, 5]))
First, lst.extend([4, 5]) executes:
List becomes: [1, 2, 3, 4, 5]
Then print() prints the return value of extend()
Which is: None
๐ Output:
None
๐น 5. Final State of List
Even though output is None, the list is updated:
print(lst)
๐ Output:
[1, 2, 3, 4, 5]

0 Comments:
Post a Comment