Python Return Statement - chrisbitm/python GitHub Wiki

[Under Construction]




A Return Statement is used to exit a Function and "hands" back a value when the Function is called. When a Return Statement is executed, the Function terminates, and the control is returned to the calling Function or the Main Program. You can also specify a Value (or multiple Values, using Tuples) to return.

def add(a, b):
    return a + b

result = add(5, 3)
print(result)

Finally, if no Return Statement is provided, the function will implicitly return None by default.

def foo():
    a = 3

bar = foo()
print(bar)
  • Variable bar will execute Function foo. the Function initializes a = 3 but once it is called, it doesn't know what to do with it. Thus, None is Output to Console

But, if you add a print() Statement. It will return that.  ```Python def foo(): a = 3

bar = foo() print(bar)