-
- Two core concepts to think about when using Python are print
and
- return
.
-
-
-
- print
takes something in your function and prints it out into your
- terminal for
- you to read. This is a great way to see what's going on inide your function while it's running.
- print
is incredibly useful for debugging, but does not provide your program with
- any useful
- information. print
is for human use only.
-
-
-
- return
is the keyword that lets Python know that you're ready to
- exit the function
- with the value on that line. return
provides useful information to the computer so
- that computed
- values can be passed from one function to another. Whenever you want to set something as the
- result of
- your function, use return
. Remember that this will exit the function. You should
- never have any
- logic in your function that is unreachable after the return
statement.
-
-
-
- Note: if you've used other programming lanugages before, you might have come across the idea of
- implicit
- returns, meaning that the last variable in the top level scope of the function will always be
- returned. This is
- not the case in Python. If you want your function to return something, you must
- always
- explicitly state it, otherwise your function will return None
.
-
-