Python Loops & Comprehensions MCQ Test: 200 Interview Questions With Answers

← All Python MCQ topics and your readiness dashboard

Test your Loops and Comprehensions 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 for and while loops, range, enumerate and zip (including strict=True), break, continue and loop else, list, dict and set comprehensions, generator expressions, any() and all(), modifying collections while iterating, late-binding closures, itertools (product, chain, groupby, pairwise, batched), polling and retry loops, and loops versus parametrize in pytest. 27 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 Loops & Comprehensions questions with answers

  • Q. A classic bug when cleaning test data. What does this code print?
    nums = [1, 2, 2, 3]
    for n in nums:
    if n == 2:
    nums.remove(n)
    print(nums)

    Answer: [1, 2, 3]
    Removing items while iterating shifts the remaining items and skips one. Build a new list instead.
  • Q. The safe way to remove items. What does this code print?
    nums = [1, 2, 2, 3]
    nums = [n for n in nums if n != 2]
    print(nums)

    Answer: [1, 3]
    A comprehension builds a new filtered list without iteration problems.
  • Q. Building a browser test matrix. What does this code print?
    from itertools import product
    for b, v in product(["chromium", "webkit"], ["desktop", "mobile"]):
    print(f"{b}-{v}", end=" ")

    Answer: chromium-desktop chromium-mobile webkit-desktop webkit-mobile
    product gives every combination, the basis of cross-browser test matrices.
  • Q. What does this code print?
    for i in range(3):
    print(i, end=" ")

    Answer: 0 1 2
    range(3) yields 0, 1 and 2; the stop value is excluded.
  • Q. What does this code print?
    print(list(range(2, 10, 3)))
    Answer: [2, 5, 8]
    Start 2, stop before 10, step 3.
  • Q. What does this code print?
    print(list(range(5, 0, -2)))
    Answer: [5, 3, 1]
    A negative step counts down; 0 is the stop and is excluded.

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 Loops & Comprehensions 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. 27 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.