1. Home
  2. Data Science
  3. Python
  4. What is the output of print([x for x in range(5) if x % 2…

Added 25 Nov 2026

What is the output of print([x for x in range(5) if x % 2 == 0]) in Python?

print([x for x in range(5) if x % 2 == 0])
  1. [0, 2, 4] Correct answer
  2. [1, 3]
  3. [0, 1, 2, 3, 4]
  4. [2, 4]

Correct answer

A. [0, 2, 4]

6 views

MCQSEXAM

Explanation

A condition at the end of a comprehension filters items.

Reference

Asked in: Python Interview Advanced Python

https://docs.python.org/3/library/index.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs