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)

30th Jul 2018, 1:34 PM
Facundo A. Ayala Alvaredo
Facundo A. Ayala Alvaredo - avatar
2 Antworten
+ 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.
30th Jul 2018, 4:46 PM
Maninder $ingh
Maninder $ingh - avatar
+ 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)
30th Jul 2018, 1:50 PM
Mishin870
Mishin870 - avatar