Functions

Functions are a way to divide your code into useful blocks which allows us to save time, order our code, reuse code and make it more understandable. Everything within a function needs to be indented the whole way through.

Functions are written by using the keyword "def" followed by the function's name. Example:

def function:

print("Hey")

Functions can also allow variables to be passed from the caller into the function. Example:

def function(name,age):

print("Hello, %s, You are %d"%(name, age))

* Once the variables outside the program (name and age) are assigned they will affect the function.*

Functions can also return values to the program using the keyword '''return. '''Example:

def function(num1,num2):

return num1 * num2

Calling Functions
Simply write the name of the function followed by, including any values that need to be placed into the brackets.

Example;

def function:

print("Hey")

function

Continue to next lesson.