Free Practice Quiz Question List

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.

20 questions
01
Choose one
1 point

Given values = ["a", "b", "c"], what does values[1] return?

  1. A

    "a"

  2. B

    "b"

  3. C

    "c"

  4. D

    An IndexError

02
True or false
1 point

True or false: In Python, (42,) is a one-item tuple, but (42) is not a tuple.

  1. A

    True

  2. B

    False

03
Choose one
1 point

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

  1. A

    [1, 2, 3]

  2. B

    [0, 1, 2]

  3. C

    [1, 2, 3, 4]

  4. D

    [2, 3, 4]

04
Written response
1 point

What list method creates a shallow copy of the outer list?

05
Fill in the blank
1 point

Complete this list comprehension: squares = [n * n n range(1, 4)].

06
Choose all
1 point

Select all correct statements about iterating over the dictionary prices = {"pen": 1.50, "notebook": 4.00}.

  1. A

    Iterating directly over a dictionary yields its keys.

  2. B

    prices.items() can be used to iterate over key-value pairs.

  3. C

    prices.values() can be used to iterate over values only.

  4. D

    Iterating directly over a dictionary always yields key-value pairs.

  5. E

    prices.items() yields only the values.

07
True or false
1 point

True or false: A for loop over a dictionary iterates over the dictionary's keys by default.

  1. A

    True

  2. B

    False

08
Written response
1 point

What integer does len([10, 20, 30, 40][1:3]) return?

09
Choose one
1 point

Which set operator should be used to find the values common to both frontend and backend?

  1. A

    |

  2. B

    &

  3. C

    -

  4. D

    ^

10
Fill in the blank
1 point

Complete the expression so that a missing key produces zero: count = word_counts.get("python", )

11
Choose all
1 point

Select all values that can be used as dictionary keys in Python.

  1. A

    A string such as "name"

  2. B

    A number such as 28

  3. C

    A tuple containing only hashable values

  4. D

    A list such as [1, 2]

  5. E

    A dictionary such as {"a": 1}

12
Open ended
1 point

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.

13
Choose one
1 point

What is printed after this code runs? bad = [[]] * 3; bad[0].append("x"); print(bad)

  1. A

    [['x'], [], []]

  2. B

    [[], ['x'], []]

  3. C

    [['x'], ['x'], ['x']]

  4. D

    An IndexError

14
Written response
1 point

What integer does this code produce? scores = [88, 91]; scores.append(82); len(scores)

15
Choose one
1 point

After this code runs, what is the value of values?

values = [3, 1, 2]

values.sort()

  1. A

    [3, 1, 2]

  2. B

    [1, 2, 3]

  3. C

    None

  4. D

    An error occurs

16
Choose one
1 point

Which expression creates a tuple containing exactly one string, "ready"?

  1. A

    ("ready")

  2. B

    ["ready"]

  3. C

    ("ready",)

  4. D

    {"ready"}

17
Choose one
1 point

What value does this expression produce?

numbers = [10, 20, 30, 40, 50, 60]

numbers[1:5:2]

  1. A

    [20, 40]

  2. B

    [10, 30, 50]

  3. C

    [20, 30, 40, 50]

  4. D

    [20, 40, 60]

18
Choose one
1 point

What does letters[-2] evaluate to?

letters = ["a", "b", "c", "d"]

  1. A

    "a"

  2. B

    "b"

  3. C

    "d"

  4. D

    "c"

19
True or false
1 point

True or false: A set supports positional indexing, so my_set[0] retrieves an arbitrary element.

  1. A

    True

  2. B

    False

20
Written response
1 point

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?