NO, a function does not always have to have an explicit return statement. If the function doesn't need to provide any results to the calling point, then the return is not needed. However, there will be a value of None which is implicitly returned by Python.
Rule 1 -- a function has a "type" -- inputs mapped to outputs. It must return a consistent type of result, or it isn't a function.
Python functions can return multiple variables. These variables can be stored in variables directly. A function is not required to return a variable, it can return zero, one, two or more variables.
Every function must have at least one return statement. A procedure is not required to have any return statements. The expression in a function's return statement must evaluate to a type that matches the return type in the function's declaration.
I just stumbled across several python programs written by different people and I noticed that every function had a return at the end of it
def function01():
# function
# events
# here
return
I was wondering if it's good python programming practice to include return at the end of functions even if it is not returning anything (purely as a way of ending the function)
Or is it not needed and nothing different will happen in the background?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With