Consider this code:
def foo(foo_input):
if 0 <= foo_input <= 100:
return f_input
This returns None in the case where foo_input > 100. But could it actually not return anything? Or does a function always have to return something?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Functions always return something (at least
None, when no return-statement was reached during execution and the end of the function is reached).Another case is when they are interrupted by exceptions.
In this case exception handling will “dominate over the stack” and you will return to the appropriate
exceptor get some nasty error 🙂Regarding your problem I must say there are two possibilities:
Either you have something to return or you do not have.
Nonewill tell the caller that this was the case (There is no better way to tell the caller that “nothing” is returned then by
None, so check for it and you will be fine)