python 3.x - Is return keyword needed in non return functions? -


i see examples return last statement in function doesn't return anything. needed in python 3.x?

def myfunc():   result = 1 + 1   return 

return statements not mandatory, if function exits without return statement, none returned.

proof:

quoting official docs, namely calls , the return statement:

about return:

return leaves current function call expression list (or none) return value.

about calls:

a call returns value, possibly none, unless raises exception. how value computed depends on type of callable object.

if user-defined function:

the code block function executed, passing argument list. first thing code block bind formal parameters arguments; described in section function definitions. when code block executes return statement, specifies return value of function call.

as can conclude docs - functions implicitly returns none, unless explicit return statement executed.


Comments