Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is Python return always necessary [duplicate]

Tags:

People also ask

Do you always need a return statement Python?

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.

Should a function always return the same type?

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.

Can return be used multiple times in Python?

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.

Does every function need a return statement?

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?