Intro to Functions
Functions are a way to group lines of code into a single block.
This is done so that code can reused, instead of typing it out over and over.
This is what a typical function looks like:
def my_function():
# some lines of code here
The def
keyword is a function definition, and tells Python that this is a function.
The name of the function is my_function
.
Usually you want to name your functions using descriptive keywords, so that you can easily identify what the function does when you use it later.
caution
Note the brackets and colon ():
after my_function
, this is extremely important!
In this tutorial, we'll learn how to create a function, and how to use it.