Given values = ["a", "b", "c"], what does values[1] return?
6 Python Collections Online Quiz Questions
Use this free practice quiz with 20 questions to review 6 Python Collections, test your knowledge, and prepare for your next test or exam.
True or false: In Python, (42,) is a one-item tuple, but (42) is not a tuple.
- A
True
- B
False
What is the result of numbers[1:4] when numbers = [0, 1, 2, 3, 4, 5]?
- A
[1, 2, 3] - B
[0, 1, 2] - C
[1, 2, 3, 4] - D
[2, 3, 4]
What list method creates a shallow copy of the outer list?
Complete this list comprehension: squares = [n * n n range(1, 4)].
Select all correct statements about iterating over the dictionary prices = {"pen": 1.50, "notebook": 4.00}.
- A
Iterating directly over a dictionary yields its keys.
- B
prices.items()can be used to iterate over key-value pairs. - C
prices.values()can be used to iterate over values only. - D
Iterating directly over a dictionary always yields key-value pairs.
- E
prices.items()yields only the values.
True or false: A for loop over a dictionary iterates over the dictionary's keys by default.
- A
True
- B
False
What integer does len([10, 20, 30, 40][1:3]) return?
Which set operator should be used to find the values common to both frontend and backend?
- A
| - B
& - C
- - D
^
Complete the expression so that a missing key produces zero: count = word_counts.get("python", )
Select all values that can be used as dictionary keys in Python.
- A
A string such as
"name" - B
A number such as
28 - C
A tuple containing only hashable values
- D
A list such as
[1, 2] - E
A dictionary such as
{"a": 1}
Explain how to choose among a list, tuple, dictionary, and set for a programming task. State the main deciding property of each collection type and include at least one suitable use case.
What is printed after this code runs? bad = [[]] * 3; bad[0].append("x"); print(bad)
- A
[['x'], [], []] - B
[[], ['x'], []] - C
[['x'], ['x'], ['x']] - D
An
IndexError
What integer does this code produce? scores = [88, 91]; scores.append(82); len(scores)
After this code runs, what is the value of values?
values = [3, 1, 2]
values.sort()
- A
[3, 1, 2] - B
[1, 2, 3] - C
None - D
An error occurs
Which expression creates a tuple containing exactly one string, "ready"?
- A
("ready") - B
["ready"] - C
("ready",) - D
{"ready"}
What value does this expression produce?
numbers = [10, 20, 30, 40, 50, 60]
numbers[1:5:2]
- A
[20, 40] - B
[10, 30, 50] - C
[20, 30, 40, 50] - D
[20, 40, 60]
What does letters[-2] evaluate to?
letters = ["a", "b", "c", "d"]
- A
"a" - B
"b" - C
"d" - D
"c"
True or false: A set supports positional indexing, so my_set[0] retrieves an arbitrary element.
- A
True
- B
False
Which built-in Python function should you use to iterate over two related collections in parallel, such as a list of names and a list of scores?
Related study packs and tools
2 Digital Logic
A 14-question medium-difficulty quiz on Boolean algebra, logic gates, truth tables, and combinational circuits.
03 — Python Programming Fundamentals
A focused set of flashcards covering Python variables, data types, expressions, control flow, functions, input, output, and common programming practices.
04 Conditionals and Boolean Logic
Learn how Boolean expressions, logical operators, and conditional structures let programs make reliable decisions, including how to handle boundaries, branch order, and testing.
6 Computer Memory
Learn how computer memory stores and addresses information, how RAM and ROM differ, and how caches and the memory hierarchy balance speed, capacity, and cost.
07 Trees and Binary Search Trees
A progressive guide to tree structure, binary-tree traversals, binary search tree operations, deletion, balancing, and the way tree height determines time and space costs.
12 — Foundations Capstone: Integrating Computer Science
A practical guide to integrating problem definition, data representation, modular programming, algorithms, complexity analysis, testing, correctness, and ethical evaluation into a responsible computer science capstone.
Interrupts
Reviews how interrupts support event handling and multitasking, and how Linux system calls use the RISC-V `ecall` instruction and register conventions.
OS Processes
This quiz covers process management, context switching and scheduling, multitasking, traps and interrupts, and RISC-V privilege transitions.
Systemcalls
A quiz on operating-system system calls, including privileged-operation requests, process creation and execution with fork, exec, and waitpid, and signal handling.