Python Practice Test: Lists and Dictionaries

  • Lists, Dictionaries, Tuples and Sets
  • 10 questions
  • 13 minutes

Ten questions on Python's built-in collections. Tip: ask yourself whether each operation changes the original object or creates a new one.

Tap an option to mark your answer. You can change your mind, or tap the same option again to leave the question blank. The correct answers and explanations appear when you finish the test.Tap an option to answer; tap it again to leave the question blank.

Advertisement
Advertisement
  1. Question 1

    nums = [4, 8, 15, 16]
    print(nums[-1], nums[1:3])

    What does the code print?

  2. Question 2

    a = [1]
    a.append([2, 3])
    print(len(a))

    What does the code print?

  3. Question 3

    d = {"a": 1}
    d["b"] = 2
    print(list(d.keys()))

    What does the code print?

  4. Question 4

    d = {"a": 1}
    print(d.get("z", 0))

    What does the code print?

  5. Question 5

    names = ["bob", "Al", "cy"]
    names.sort()
    print(names)

    What does the code print?

  6. Question 6

    print([x * x for x in range(5) if x % 2 == 0])

    What does the code print?

  7. Question 7

    t = (1, 2, 3)
    t[0] = 9

    What happens when this code runs?

  8. Question 8

    print(len({1, 2, 2, 3, 3, 3}))

    What does the code print?

  9. Question 9

    nums = [1, 2, 3]
    print(nums.pop(0), nums)

    What does the code print?

  10. Question 10

    a = [1, 2, 3]
    b = a[:]
    b[0] = 99
    print(a)

    What does the code print?

Questions you leave blank are not counted as wrong.

Advertisement

More Python tests

All Python Programming tests
13:00

Do you want to finish the test?