Lists & Tuples · Question 10 · Medium
remove() and pop() are used on a queue of token numbers. What does this print?
q = [10, 20, 30, 20]
q.remove(20)
x = q.pop()
print(q, x)
- [10, 30, 20] 20
- [10, 30] 20
- [10, 30] 30
- [10, 20, 30] 20
Answer and explanation
Answer: B. [10, 30] 20
Explanation: remove(20) deletes only the first 20, leaving [10, 30, 20]. pop() with no argument removes and returns the last element, 20, so the list is [10, 30].
Previous: One name is a slice copy of the list a and another is a plain assignment. What… · Next: A starred name is used while unpacking a list. What is printed?
Practise lists & tuples
Try a fresh set of lists & tuples questions with an explanation after every answer, free and without signing up: Lists & Tuples practice. Or sit a full placement mock test.
More lists & tuples questions
- Two variables are exchanged using tuple packing and unpacking. What is printed?
- The same list goes through sorted() and then sort(). What does this print?
- One name is a slice copy of the list a and another is a plain assignment. What…
- A starred name is used while unpacking a list. What is printed?
- For the tuple t = (1, 2, 3), which of these operations is NOT allowed?
- A marks table is stored as a list of rows. What does this print?
- Kavya has a list a and wants b to be a separate list with the same items, so…
- A two-element slice of a list is replaced by a one-element list. What is…
- The list a is extended once with + and once with += through a second name…
- Even numbers are removed from a list while a for loop is running over it. What…
More python practice
Dictionaries & Sets · Conditions & Loops · Functions & Scope · Comprehensions & Generators · Classes & Objects · Exceptions & Files · Built-ins & Standard Library · Variables, Types & Operators
LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge