CBSE Class 10 Computer Applications Question 7 of 26

Python Conditionals and Loops — Question 5

Back to all questions
5
Question

Question 5

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
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.