QuestionQ201

VerifiedControl Flow – Conditional Blocks and Loops

What is the expected output from the following code?

print(len([i for i in range(0, -2)]))  
Explanation

With its default step of 1, range(0, -2) is empty because it cannot advance upward from 0 toward the exclusive stop value -2. The list comprehension produces an empty list, so len(...) returns 0.

Community Discussion

No comments yet. Be the first to start the discussion!