Show Menu
Cheatography

Python Functions Cheat Sheet (DRAFT) by

Cheet sheet about python functions

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 Inform­ation 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 inform­ation the function needs to do its job. The value
'jesse' in greet_­use­r('­jesse') is an example of an argument. An argument
is a piece of inform­ation 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