Python Dictionaries & Sets MCQ Test: 200 Interview Questions With Answers

← All Python MCQ topics and your readiness dashboard

Test your Dictionaries and Sets knowledge with a timed Python MCQ mock test for interviews. Each attempt gives you 20 random questions in 20 minutes from a 200-question bank covering dict lookups, get, pop, setdefault and update, the | merge operator, comprehensions, views, hashing and valid keys, copies, JSON round trips, defaultdict, Counter, OrderedDict and ChainMap, set algebra and frozenset, and API testing with dicts and sets: subset checks, missing and extra fields, duplicates, masking secrets and config overrides. 40 questions are written from a QA and test-automation angle and the rest from a developer angle; your result shows both scores.

What this Python MCQ test covers

Revise these lessons from the free Python tutorial before or after your test:

Sample Python Dictionaries & Sets questions with answers

  • Q. Summarising a test run. What does this code print?
    from collections import Counter
    results = ["passed", "failed", "passed", "passed", "skipped"]
    c = Counter(results)
    print(f"{c['passed']}/{len(results)} passed, {c['failed']} failed")

    Answer: 3/5 passed, 1 failed
    Counter turns a list of statuses into a summary in one line.
  • Q. Reading an optional field from an API response. What does this code print?
    resp = {"data": {"user": {"id": 7}}}
    email = resp.get("data", {}).get("user", {}).get("email", "n/a")
    print(email)

    Answer: n/a
    Chained get() calls with {} defaults avoid KeyError for optional fields.
  • Q. Checking an API payload. What does this code print?
    expected = {"id": 7, "name": "Asha"}
    actual = {"id": 7, "name": "Asha", "created": "2026-01-01"}
    print(expected.items() <= actual.items())

    Answer: True
    An items-view subset check confirms every expected pair is present, ignoring extra fields.
  • Q. What does this code print?
    d = {"a": 1, "b": 2}
    print(d["b"], len(d))

    Answer: 2 2
    Look up a value by key; len() counts the keys.
  • Q. What does this code print?
    d = {"a": 1}
    try:
    d["z"]
    except KeyError as e:
    print("KeyError", e)

    Answer: KeyError 'z'
    A missing key raises KeyError; the message is the repr of the key.
  • Q. What does this code print?
    d = {"a": 1}
    print(d.get("z"), d.get("z", 0))

    Answer: None 0
    get returns None, or the default you pass, instead of raising.

Every predict-the-output question in this bank was run on Python 3, so the answer is the real output. Go back to the Python MCQ dashboard to see your overall Python learning progress and interview readiness.

Frequently asked questions

How many questions does the Python Dictionaries & Sets MCQ test have?

The bank has 200 questions. Each test picks 20 at random, favouring questions you have not seen yet, so about 10 attempts cover the whole bank.

How long is each test and what is the pass mark?

Each test has a 20-minute timer and submits itself when time runs out. You pass with 70%, which is 14 of 20 correct.

Is this test useful for QA and automation engineer interviews?

Yes. 40 of the questions use test-automation scenarios such as parsing UI text, test data and assertions, and your result shows your QA score separately.

Can I retake the test?

Yes, as often as you like. Every retake draws a fresh set of 20 questions and counts toward your 20-test readiness target.