Keywords and Control Flow
return — Function completion
Leave the current function and deliver a result to the caller. A bare return or falling off an ordinary function body produces None. A comma-separated result is a tuple. Cleanup in an active finally suite happens before leaving; a return or exception from that cleanup can change the outcome. In synchronous generators, a return value becomes StopIteration.value rather than another yielded item. In asynchronous generators, a return with a value is a syntax error.
Formal Syntax & Structure
python syntaxpython
returnreturn expression_listWorking Example
Example Snippetpython
def classify(quantity): if quantity <= 0: return "empty" return "available", quantity
print(classify(0))print(classify(3))