Question 1
Back to Exercise
What is the output of the following Python program?
a = [1, 2, 3]
a.append([4, 5])
b = [1, 2, 3]
b.extend([4, 5])
print(len(a), len(b), a[-1], b[-1])
- A 5 5 5 5
- B 4 4 [4, 5] [4, 5]
- C 5 4 5 [4, 5]
- D 4 5 [4, 5] 5 Correct
Correct Answer: Option D
append adds the whole list as one item; extend adds 4 and 5 separately.
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!