+ 2

Can anyone explain?

def print_nums(x): for i in range(x): print(i) return print_nums(10) why is the result 0?

18th Sep 2017, 10:25 PM
Duma Cristian
Duma Cristian - avatar
5 Risposte
+ 2
Because of the return. It acts like a break within a function. Remove the keyword it would work
18th Sep 2017, 10:27 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 2
Great advice,thanks sir
18th Sep 2017, 10:29 PM
Duma Cristian
Duma Cristian - avatar
+ 1
Return is not necessary for a function in Python, unlike some other languages
18th Sep 2017, 10:28 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
Pls JUST DON'T SAY SIR. I am just 14
18th Sep 2017, 10:30 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 1
I look old if you say that. I like being young 😂😂😂
18th Sep 2017, 10:30 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar