CBSE Class 12 Computer Science Question 41 of 120

Review of Python Basics — Question 15

Back to all questions
15
Question

Question 15

Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

  1. [0, 1, 2, 3]
  2. [0, 1, 2, 3, 4]
  3. [0.0, 0.5, 1.0, 1.5]
  4. [0.0, 0.5, 1.0, 1.5, 2.0]
Answer

[0.0, 0.5, 1.0, 1.5]

Reason — The list comprehension [0.5 * x for x in range(0, 4)] generates a list by calculating 0.5 * x for each value of x in the range from 0 to 3 (not including 4), which results in the list [0.0, 0.5, 1.0, 1.5].