Functions
Functions are like recipes, they store your Python instructions and allow us to reuse them again and again.
To create a function, we start with def, a function name, a pair of parentheses (), and a colon :. We then write the code we want below this line with an indent. Here's an example...
def make_a_cake():
print("Here's your cake!")
The code above creates a function named make_a_cake, and the function contains the code print("Here's your cake!"). To run this function, we would type in the function name followed by the paretheses...
make_a_cake()
In our previous exercises, we have used print(), turtle.penup(), turtle.forward() and so on. These are all functions.
Here's a complete example...
Once a function is created, we can run it multiple times...
We can also have more than just print statements inside our function. Everything we have learned can be use in a function as well!