What is the value of values[1:4] when values = [0, 1, 2, 3, 4, 5]?
5 Collections and String Processing Online Quiz Questions
Use this free practice quiz with 20 questions to review 5 Collections and String Processing, test your knowledge, and prepare for your next test or exam.
True or false: After text = "hello"; result = text.upper(), the original variable text still refers to the lowercase string "hello".
- A
True
- B
False
Which Python string method would you use to change every occurrence of "cat" to "dog" in a string?
What value is assigned to email by this code when student = {"name": "Ada"}?
email = student.get("email")
Answer:
A program receives usernames that may contain duplicates and needs to test quickly whether a username has already appeared. Which collection is the most appropriate?
- A
A list
- B
A tuple
- C
A set
- D
A dictionary
Which two of the following listed collection types are ordered sequences that support indexing? Select all correct choices.
- A
A list
- B
A set
- C
A tuple
- D
A dictionary
True or false: Because modern Python dictionaries preserve insertion order, a dictionary can generally replace a list when numeric positions and slicing are central to a problem.
- A
True
- B
False
What Python collection is generally more suitable than a list for a queue that frequently adds and removes items at both ends?
What is the result of this list comprehension?
squares = [number ** 2 for number in range(5) if number % 2 == 0]
Answer:
Which expression can be used as a dictionary key?
- A
([10, 20],) - B
(10, 20) - C
{10, 20} - D
[10, 20]
Which two statements correctly describe iteration tools from the material? Select all correct choices.
- A
enumerate(colors)can provide each index and color. - B
zip(names, ages)can provide corresponding name–age pairs. - C
colors.index()is required to iterate through positions and values. - D
zip()can only combine dictionaries, not lists.
A registration system must support two operations: checking whether a username is already registered, and retrieving the profile associated with a username. Explain which collection is appropriate for each operation and why. Also state what dictionary-based technique can remove duplicates from a list while preserving their first-seen order.
What is assigned to item after this code runs?
stack = []stack.append("first")stack.append("second")item = stack.pop()
- A
"first" - B
Both items at once
- C
"second" - D
No item;
pop()only reads the list
A program needs to store usernames without duplicates and repeatedly test whether a username is already registered. Which Python collection is the most appropriate choice?
- A
list
- B
tuple
- C
set
- D
dictionary
True or false: In Python, the stop index of a slice is excluded from the resulting sequence.
- A
True
- B
False
What collection type is returned by "Ada,Grace,Linus".split(",")?
Given profile = {"name": "Ada"}, what does profile.get("country", "Unknown") return?
- A
None
- B
"Unknown"
- C
KeyError
- D
False
What happens when this code runs?
point = (3, 4)
point[0] = 10
- A
The tuple changes to
(10, 4) - B
The assignment is silently ignored
- C
A
TypeErroris raised - D
A
KeyErroris raised
What is the zero-based index of the final character in the string "Python"?
What is the value of evens after this statement executes?
evens = [number for number in range(10) if number % 2 == 0]
- A
[1, 3, 5, 7, 9] - B
[0, 2, 4, 6, 8] - C
[2, 4, 6, 8, 10] - D
[0, 1, 2, 3, 4]
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.