Can you help me with this question ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can you help me with this question ?

x=2 for i in range (x); x+=1 Print (x) *Why the answer is 4 ?

21st Aug 2019, 10:49 AM
Que
1 Answer
+ 2
for i in range(x) - runs x times (2) It adds 2 to x two times. Primitive values are passed by value, so this doesn't cause an infinite loop if that's what you thought
21st Aug 2019, 10:52 AM
Airree
Airree - avatar