can someone answer to me how i get 0 in this code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can someone answer to me how i get 0 in this code

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

16th Nov 2020, 8:04 AM
pyae phyo
pyae phyo - avatar
2 Answers
+ 1
range(10) yields values in range 0 ; 9. The return keyword is used to exit directly a function call, so the loop runs once and prints 0, then exit.
16th Nov 2020, 8:21 AM
Théophile
Théophile - avatar