Learn with Yasir

Share Your Feedback

Python List Comprehension MCQs – Multiple Choice Questions for Practice and Learning

Test and improve your understanding of Python dictionaries with these multiple choice questions. Practice key concepts like key-value pairs, dictionary methods, and data manipulation with beginner-friendly MCQs and detailed answers. Ideal for students and Python learners.

Topic: list-comprehension


📝 Multiple Choice Questions

🟢 Beginner

Q1. What is the output of this list comprehension?

print([x * 2 for x in range(3)])
  • 🟢 A. [0, 2, 4]
  • 🔵 B. [2, 4, 6]
  • 🟠 C. [1, 2, 3]
  • 🔴 D. [0, 1, 2]
Answer

[0, 2, 4]

Each number in range(3) is multiplied by 2: [0*2, 1*2, 2*2].


Q2. What will the following list comprehension produce?

print([char for char in "abc"])
  • 🟢 A. ['a', 'b', 'c']
  • 🔵 B. [97, 98, 99]
  • 🟠 C. ['abc']
  • 🔴 D. ['a b c']
Answer

['a', 'b', 'c']

It iterates through each character in the string 'abc'.


Q3. What does this comprehension return?

print([x.upper() for x in ["a", "b", "c"]])
  • 🟢 A. ['A', 'B', 'C']
  • 🔵 B. ['a', 'b', 'c']
  • 🟠 C. ['a.upper()', 'b.upper()', 'c.upper()']
  • 🔴 D. [A, B, C]
Answer

['A', 'B', 'C']

The upper() method is applied to each string.


Q4. Which statement is equivalent to list comprehension?

result = []
for x in range(3):
    result.append(x + 1)
  • 🟢 A. [x + 1 for x in range(3)]
  • 🔵 B. [x for x in range(3)]
  • 🟠 C. [x * 1 for x in range(3)]
  • 🔴 D. [x + 2 for x in range(3)]
Answer

[x + 1 for x in range(3)]

The for loop appends x+1, which matches this comprehension.


🟡 Intermediate

Q1. What does this list comprehension filter?

numbers = [1, 2, 3, 4, 5]
print([x for x in numbers if x % 2 == 0])
  • 🟢 A. [1, 3, 5]
  • 🔵 B. [2, 4]
  • 🟠 C. [2, 3, 4]
  • 🔴 D. [1, 2, 3, 4, 5]
Answer

[2, 4]

It filters only even numbers using the condition `x % 2 == 0`.


Q2. What is the result of this list comprehension?

print([x for x in range(10) if x % 3 == 0])
  • 🟢 A. [3, 6, 9]
  • 🔵 B. [0, 3, 6, 9]
  • 🟠 C. [1, 4, 7]
  • 🔴 D. [0, 2, 4, 6, 8]
Answer

[0, 3, 6, 9]

It includes numbers divisible by 3 from 0 to 9.


Q3. What will be the output?

print([i for i in range(5) if i not in [1, 3]])
  • 🟢 A. [0, 1, 2, 3, 4]
  • 🔵 B. [0, 2, 4]
  • 🟠 C. [1, 3]
  • 🔴 D. [2, 4]
Answer

[0, 2, 4]

It excludes 1 and 3 from the list.


Q4. How many elements will this produce?

print([x**2 for x in range(4)])
  • 🟢 A. 4
  • 🔵 B. 3
  • 🟠 C. 5
  • 🔴 D. 0
Answer

4

range(4) produces 0, 1, 2, 3 → four elements.


Q5. What is the output?

print([i for i in range(5) if i % 2])
  • 🟢 A. [0, 2, 4]
  • 🔵 B. [1, 3]
  • 🟠 C. [0, 1, 2, 3, 4]
  • 🔴 D. [2, 4]
Answer

[1, 3]

i % 2 is true for odd numbers.


Q6. Which of the following generates a list of squares of even numbers only?

result = [x**2 for x in range(10) if x % 2 == 0]
print(result)
  • 🟢 A. [1, 3, 5, 7, 9]
  • 🔵 B. [0, 4, 16, 36, 64]
  • 🟠 C. [0, 2, 4, 6, 8]
  • 🔴 D. [2, 4, 6, 8]
Answer

[0, 4, 16, 36, 64]

Even numbers from 0 to 9 are squared.


Q7. What is the result of this code?

print([x for x in range(5) if x])
  • 🟢 A. [0, 1, 2, 3, 4]
  • 🔵 B. [1, 2, 3, 4]
  • 🟠 C. [0]
  • 🔴 D. [5]
Answer

[1, 2, 3, 4]

In Python, 0 is considered False in a boolean context.


🔴 Advanced

Q1. What is the output of this nested list comprehension?

print([x*y for x in [1, 2] for y in [10, 100]])
  • 🟢 A. [10, 100, 20, 200]
  • 🔵 B. [10, 20, 100, 200]
  • 🟠 C. [1, 2, 10, 100]
  • 🔴 D. [1000, 2000]
Answer

[10, 100, 20, 200]

It evaluates 1*10, 1*100, 2*10, 2*100 in that order.


Q2. What will be the result?

print([x+y for x in 'ab' for y in '12'])
  • 🟢 A. ['a1', 'a2', 'b1', 'b2']
  • 🔵 B. ['ab12']
  • 🟠 C. ['a', 'b', '1', '2']
  • 🔴 D. ['a12', 'b12']
Answer

['a1', 'a2', 'b1', 'b2']

It produces all combinations of characters from both strings.


Q3. What will this produce?

print([[i, j] for i in range(2) for j in range(2)])
  • 🟢 A. [[0, 0], [0, 1], [1, 0], [1, 1]]
  • 🔵 B. [[0, 0], [1, 1]]
  • 🟠 C. [[0, 1], [1, 2]]
  • 🔴 D. [[1, 0], [2, 1]]
Answer

[[0, 0], [0, 1], [1, 0], [1, 1]]

It generates all pairs (i, j) from 0 and 1.


Q4. What does the following comprehension return?

print([i.lower() for i in "HELLO" if i not in "EO"])
  • 🟢 A. ['h', 'l', 'l']
  • 🔵 B. ['H', 'L', 'L']
  • 🟠 C. ['HELLO']
  • 🔴 D. ['e', 'o']
Answer

['h', 'l', 'l']

It skips 'E' and 'O', and converts remaining to lowercase.


Explore More Topics

📘 Learn Python

Tutorials, Roadmaps, Bootcamps & Visualization Projects

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




🧠 Python Advanced

Object-Oriented Programming in Python (OOP)

More...

🧠 Modules