Dec-01-2020, 06:32 PM
Hello,
I have this simple example where I simple want to exit a function when i == 5.
I always use return to exit, but I an not sure what is happening here.
thx
I have this simple example where I simple want to exit a function when i == 5.
def foo(i):
print i, "--"
if i < 5:
foo(i+1)
print "++++++"
elif i == 5:
print "xxxxxx"
return "what ever"
print "why is this printing?"
x = foo(3)
print x
# Result:
3 --
4 --
5 --
xxxxxx
++++++
why is this printing?
++++++
why is this printing?
None <-----2 things I don't get. 1-why is it not exiting the function? The fact that it is printing the last line shows that it is not exiting after return right? 2-(which I guess is derived from 1), why x is None when the return is "what ever"I always use return to exit, but I an not sure what is happening here.
thx
