While every function might not have an explicit return it will have an implicit one, that is None
, which incidentally is a normal Python object. Further, functions often return None
explicitly.
I suppose returning None implicitly is just an ease-of-use optimisation.
P.S. I wonder what you propose compile would do in the following case:
def t():
if True:
return 'ham'
P.P.S. return
statement indicates that something needs to be returned, be it None
, 42
or 'spam'
. Some functions, however, don't really return anything, like list.sort
or __init__
, therefore it would be an overhead to require a return None
statement at the end of each __init__
.