KnowledgeBoat Logo

Computer Applications

What will be the output of following code ?

for i in range(1) : 
    print i
  1. 0
  2. 1
  3. No output
  4. Error in code

Python Control Flow

1 Like

Answer

0

Reason — The range(n) function generates a list as [0, 1, 2…, n - 1]. Thus, the range(1) function will generate a list as [0]. Thus the for loop will execute only one time and print 0 on the output terminal.

Answered By

2 Likes


Related Questions