+ 1

Why is the fuction returning a 0 and None instead of the numbers within the range.

>>> def print_nums(x): for i in range(10): print(i) return >>> print(print_nums(4)) 0 None

7th Jan 2018, 11:36 AM
Kane A. Scott
Kane A. Scott - avatar
2 ответов
+ 12
It will print 0 because of the for loop. then, the execution will immediately stop because of return. And the function is returning nothing. And you are trying to print nothing. Because of this, None is printed.
7th Jan 2018, 11:41 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 12
remove return and just use print_nums(4) not print(print_nums(4))
7th Jan 2018, 11:42 AM
Swapnil Srivastava
Swapnil Srivastava - avatar