What will be the output of the following code?i = 3for i in range (4) print (i) 0 1 2 3 1 2 3 4 3 4 5 6 3 2 1 0
Question
What will be the output of the following code?i = 3for i in range (4) print (i) 0 1 2 3 1 2 3 4 3 4 5 6 3 2 1 0
Solution
The output of the given code will be:
0 1 2 3
This is because the range function in Python starts from 0 and goes up to (but does not include) the number specified, which in this case is 4. The variable 'i' is initially set to 3, but this value is overwritten by the for loop.
Similar Questions
What is the output of the following Python code?for i in range(5,0,-1): print(i)5 4 3 2 11 2 3 4 55 5 5 5 51 1 1 1 1
What will be printed by the following code?for i in range(5): for j in range(5, 0, -1): if i == j: print(i, end=" ")1 2 3 44 3 2 1 004
What will the following code generate?for i in range(0, 12, 3): print(i)A.0 1 2 3 4 5 6 7 8 9 10 11B.0 3 6 9C.0 1 2 3 4 5 6 7 8 9 10 11 12D.0 3 6
Question 18What code segment would output the following?2341 pointfor i in range(1,5): if (i!=2): print(i)for i in range(1,5): if (i!=1): print(i)for i in range(1,5): if (i==2): print(i)
9. What will be the output of the following Python code?x = (i for i in range(3))for i in x: print(i)for i in x: print(i)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.