Step-by-Step Execution:
Function Definition:
- The function extend_list(lst) takes a list lst as an argument.
- It uses .extend([10]), which appends 10 to the existing list.
List Initialization:
- A list b is created with four elements: [5, 10, 15, 20].
- Initially, len(b) = 4.
Function Call:
- The list b is passed to extend_list(lst).
- Inside the function, lst.extend([10]) adds 10 to the end of b.
- Now, b becomes [5, 10, 15, 20, 10].
Printing the Length:
- The updated list has 5 elements: [5, 10, 15, 20, 10].
- len(b) returns 5.
Function Definition:
- The function extend_list(lst) takes a list lst as an argument.
- It uses .extend([10]), which appends 10 to the existing list.
List Initialization:
- A list b is created with four elements: [5, 10, 15, 20].
- Initially, len(b) = 4.
Function Call:
- The list b is passed to extend_list(lst).
- Inside the function, lst.extend([10]) adds 10 to the end of b.
- Now, b becomes [5, 10, 15, 20, 10].
Printing the Length:
- The updated list has 5 elements: [5, 10, 15, 20, 10].
- len(b) returns 5.
Final Output:
Key Points:
- .extend([10]) appends 10 to the list.
- Since lists are mutable, b is modified directly.
- The function does not return a new list; it updates the existing list.
- len(b) increases from 4 to 5 after the function call.