0
I need a further explanation of how this works for the result to be 0?
What is the highest number output by this code? def print_nums(x): for i in range(x): print(i) return print_nums(10)
2 ответов
+ 2
remember that when return line is execute in function after that function stops his work when i==0 and print it then after that there is return statement and function stops his working.
+ 1
Briefly: because of the return
Longer:
The function range(x) returns a list of numbers from 0 to x - 1
Your loop goes through all the elements of this list, starting with the first (the number 0)
At the end of the loop body is the return operator, which stops the execution of the entire function (print_nums)