Question 14
Back to Exercise
What is the output of the following Python program?
def modify(lst, n):
lst.append(4)
n += 1
lst = [0]
nums = [1]
k = 1
modify(nums, k)
print(nums, k)
- A [0] 2
- B [1, 4] 2
- C [1] 1
- D [1, 4] 1 Correct
Correct Answer: Option D
append changes the caller's list. n += 1 and lst = [0] only rebind local names.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!