1. Home
  2. Data Science
  3. Python
  4. What does [x * x for x in range(4)] produce?

Added 2 Nov 2026

What does [x * x for x in range(4)] produce?

  1. [0, 1, 4, 9] Correct answer
  2. [0, 2, 4, 6]
  3. [0, 1, 2, 3]
  4. [1, 4, 9, 16]

Correct answer

A. [0, 1, 4, 9]

16 views

MCQSEXAM

Explanation

range(4) yields 0, 1, 2 and 3, and the list comprehension squares each one. Forgetting that range starts at 0 gives the wrong answer [1, 4, 9, 16].

Reference

Asked in: NTS, PPSC, Python Developer Interviews

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