PCEP 30 02 PCEP Certified Entry Level Python Programmer · Free Practice Question Medium
Question 16
What is the output of the following code snippet?
- List = ['p','q']
- List.append('r')
- List.append([10,20,30])
- List.extend([200,500])
- print(List)
-
A
['p', 'q', ['r'], [10, 20, 30], 200, 500]
-
B
['p', 'q', 'r', [10, 20, 30], 200, 500]
-
C
['p', 'q', 'r', 10, 20, 30, 200, 500]
-
D
['p', 'q', ['r'], [10, 20, 30], 200, 500]
Reveal correct answer
Correct answer: B
Explanation
append() function add the entire data at the last.
List.append('r') #adds element 'r' to the list at end
List.append([10,20,30]) #adds list 10,20,30] to the list at end
extend() function adds the elements one by one till last.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
You must be logged in to post a comment.
