Functions that Don't Return Anything
A curious sub-category of functions in Python.
A function, typically, returns a value. Keyword: "typically". Consider a function like so:
This is a completely valid function that takes in a value
xand prints it. Notice how this function does not return anything.
Now, for a contradictory fact: all Python functions return a value.
How does this work? When we don't return any value, Python does it for us. Let's try this in our interpreter.
>>> def f(x):
>>> ... print(x)
>>> r_val = f("hi")
You'll notice how prompting
r_valon the terminal does not return anything — this is because
This, we now know a deep fact about Python — that it implicitly returns
Nonewhen no other value is returned.
# return None # implicitly!