Can someone explain it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone explain it?

def print_nums(x): for i in range(x): print(i) return print_nums(10)

27th Sep 2020, 9:43 AM
Anish Chhabra
Anish Chhabra - avatar
2 Answers
+ 8
Anish Chhabra Output is 0 You have passed 10 and used for loop from 0 to 10 range then you printed and returned from the function in the very first iteration so, it will print only 0.
27th Sep 2020, 9:55 AM
chaithra Gowda
chaithra Gowda - avatar
+ 2
The for loop only run once. It prints i whereas i is 0. And return which ends the function. No matter how big the number is you passed to the function. It's always 0.
27th Sep 2020, 10:21 AM
你知道規則,我也是
你知道規則,我也是 - avatar