Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

What is the value of values[1:4] when values = [0, 1, 2, 3, 4, 5]?

  1. A

    [0, 1, 2, 3]

  2. B

    [1, 2, 3]

  3. C

    [1, 2, 3, 4]

  4. D

    [2, 3, 4]

02
True or false
1 point

True or false: After text = "hello"; result = text.upper(), the original variable text still refers to the lowercase string "hello".

  1. A

    True

  2. B

    False

03
Written response
1 point

Which Python string method would you use to change every occurrence of "cat" to "dog" in a string?

04
Fill in the blank
1 point

What value is assigned to email by this code when student = {"name": "Ada"}?

email = student.get("email")

Answer:

05
Choose one
1 point

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?

  1. A

    A list

  2. B

    A tuple

  3. C

    A set

  4. D

    A dictionary

06
Choose all
1 point

Which two of the following listed collection types are ordered sequences that support indexing? Select all correct choices.

  1. A

    A list

  2. B

    A set

  3. C

    A tuple

  4. D

    A dictionary

07
True or false
1 point

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.

  1. A

    True

  2. B

    False

08
Written response
1 point

What Python collection is generally more suitable than a list for a queue that frequently adds and removes items at both ends?

09
Fill in the blank
1 point

What is the result of this list comprehension?

squares = [number ** 2 for number in range(5) if number % 2 == 0]

Answer:

10
Choose one
1 point

Which expression can be used as a dictionary key?

  1. A

    ([10, 20],)

  2. B

    (10, 20)

  3. C

    {10, 20}

  4. D

    [10, 20]

11
Choose all
1 point

Which two statements correctly describe iteration tools from the material? Select all correct choices.

  1. A

    enumerate(colors) can provide each index and color.

  2. B

    zip(names, ages) can provide corresponding name–age pairs.

  3. C

    colors.index() is required to iterate through positions and values.

  4. D

    zip() can only combine dictionaries, not lists.

12
Open ended
1 point

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.

13
Choose one
1 point

What is assigned to item after this code runs?

stack = []
stack.append("first")
stack.append("second")
item = stack.pop()

  1. A

    "first"

  2. B

    Both items at once

  3. C

    "second"

  4. D

    No item; pop() only reads the list

14
Choose one
1 point

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?

  1. A

    list

  2. B

    tuple

  3. C

    set

  4. D

    dictionary

15
True or false
1 point

True or false: In Python, the stop index of a slice is excluded from the resulting sequence.

  1. A

    True

  2. B

    False

16
Written response
1 point

What collection type is returned by "Ada,Grace,Linus".split(",")?

17
Choose one
1 point

Given profile = {"name": "Ada"}, what does profile.get("country", "Unknown") return?

  1. A

    None

  2. B

    "Unknown"

  3. C

    KeyError

  4. D

    False

18
Choose one
1 point

What happens when this code runs?

point = (3, 4)

point[0] = 10

  1. A

    The tuple changes to (10, 4)

  2. B

    The assignment is silently ignored

  3. C

    A TypeError is raised

  4. D

    A KeyError is raised

19
Written response
1 point

What is the zero-based index of the final character in the string "Python"?

20
Choose one
1 point

What is the value of evens after this statement executes?

evens = [number for number in range(10) if number % 2 == 0]

  1. A

    [1, 3, 5, 7, 9]

  2. B

    [0, 2, 4, 6, 8]

  3. C

    [2, 4, 6, 8, 10]

  4. D

    [0, 1, 2, 3, 4]