Python Fundamentals · Practice set 8 of 8
Lists, Stacks, and Queues: 10 practice questions
10 free Python Fundamentals practice questions on Lists, Stacks, and Queues, with an explanation for every answer. Untimed. The full mock exam and the timed version are in the app.
-
Question 1 of 10
Which list method adds one item to the end of an existing list?
- ACall `append(value)` on the list.
- BCall `extend(value)` on the list.
- CCall `count(value)` on the list.
- DCall `insert(0, value)` on the list.
Show the answer
`append()` performs the single-item end mutation; `extend()` consumes an iterable, while `count()` only reports occurrences.
Next → 1 / 10 -
Question 2 of 10
What does `items.pop()` do when `items` is a nonempty list?
- AIt removes every item and returns `None`.
- BIt removes and returns the first item.
- CIt removes and returns the last item.
- DIt returns the last item without removing it.
Show the answer
The default index for `pop()` is the final position, and the removed object is the method's return value.
Next → 2 / 10 -
Question 3 of 10
What is the effect of `del records` on the variable name `records`?
- AThe name is deleted, so a later reference is an error until reassignment.
- BThe final list item is removed and returned.
- CThe list remains bound to the name but becomes empty.
- DThe first list item is removed while the name remains bound.
Show the answer
Applying `del` to a bare name removes that name; clearing list contents instead requires a list target such as a full slice.
Next → 3 / 10 -
Question 4 of 10
A list must receive each element from another iterable as a separate new item. Which method fits?
- AUse `remove(iterable)`.
- BUse `extend(iterable)`.
- CUse `count(iterable)`.
- DUse `append(iterable)`.
Show the answer
`extend()` consumes the iterable and appends all of its items; `append()` would add its argument as one item.
Next → 4 / 10 -
Question 5 of 10
How does `values.remove(target)` behave when `target` appears more than once?
- AIt deletes every equal item and returns their former count.
- BIt deletes the final equal item and leaves earlier matches in place.
- CIt deletes the first equal item and leaves later matches in place.
- DIt returns the first matching index without changing the list.
Show the answer
`remove()` is a value-based mutation of the first match; `index()` is the neighboring operation that reports a position.
Next → 5 / 10 -
Keep the ones you got wrong
In the app, every question you miss comes back exactly when you’re about to forget it.
-
Question 6 of 10
After `result = names.sort()`, which statement describes the documented behavior?
- A`names` is reversed in place and `result` is the list.
- B`result` is a sorted copy while `names` is unchanged.
- C`result` is the removed final item while `names` becomes shorter.
- D`names` is sorted in place and `result` is `None`.
Show the answer
`sort()` is an in-place mutation and follows the mutable-structure design principle of returning `None`.
Next → 6 / 10 -
Question 7 of 10
Which operation removes the item at index 2 without producing that item as a return value?
- AExecute `values.remove(2)`.
- BExecute `del values[2]`.
- CExecute `values.pop(2)`.
- DExecute `values.index(2)`.
Show the answer
An indexed `del` targets a position and has no removed-value result; `pop()` targets a position but returns the item.
Next → 7 / 10 -
Question 8 of 10
An undo history adds each new action at one end and must retrieve the most recently added action before older ones. Which pair meets both constraints?
- AAdd with `insert(0, action)` and retrieve with index-free `pop()`.
- BAdd with `append()` and retrieve with index-free `pop()`.
- CAdd with `append()` and retrieve with `pop(0)` from the front.
- DAdd with `extend(action)` and retrieve with `remove(action)`.
Show the answer
A list-backed stack keeps both operations at the end: `append()` adds the newest item and index-free `pop()` returns it first.
Next → 8 / 10 -
Question 9 of 10
A busy service must process arrivals in their original order and frequently add and remove items without shifting the remaining elements. Which design fits?
- AUse a `collections.deque`, adding and removing with index-free `pop()`.
- BUse a `collections.deque`, adding with `append()` and removing with `popleft()`.
- CUse a list, adding with `append()` and removing with `pop(0)`.
- DUse a list, adding with `insert(0, item)` and removing with `pop()`.
Show the answer
A deque supplies first-in, first-out retrieval through `popleft()` and is designed for fast operations at both ends.
Next → 9 / 10 -
Question 10 of 10
A cleanup must remove positions 2 through 4 from `records`, leave the same name usable, and ignore the removed values. Which statement satisfies all constraints?
- AExecute `del records` and then refer to `records`.
- BExecute `del records[2:5]` while retaining the name.
- CExecute `records.remove(2:5)` and keep using the list.
- DExecute `records.pop(2:5)` and ignore its result.
Show the answer
A slice target with `del` removes the selected positions without returning values and preserves the variable binding.
Next → 10 / 10 -
You’ve finished this set
That’s 10 questions on Lists, Stacks, and Queues. In the app the ones you miss come back exactly when you’re about to forget them.
The whole course, on your phone
Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.