This is a draft cheat sheet. It is a work in progress and is not finished yet.
Defining a function
# Exampe
def greet_user():
"""Display a simple greeting."""
print("Hello!")
greet_user()
|
Passing Information to a Function
def greet_user(username):
"""Display a simple greeting."""
print("Hello, " + username)
greet_user('jesse')
|
|
|
variable username
he variable username in the definition of greet_user() is an example of a
parameter, a piece of information the function needs to do its job. The value
'jesse' in greet_user('jesse') is an example of an argument. An argument
is a piece of information that is passed from a function call to a function. |
Passing Arguments
We pass infomation to a function using parameters and arguments |
|
|
keyword arguments
if you combine both positional and keyword arguments when calling a function, then make sure keyword arguments come after positional arguments. If they come before, you'll get an error |
|