November 2017
Beginner to intermediate
204 pages
5h 23m
English
A function is a labeled block of code that can be used at any point throughout the program. A function in Python follows the following syntax:
def <nameOfFunction>(<parameters>): <code block>
Notice the parentheses following the name of the function. Inside the parentheses, it is possible to specify certain variables called parameters or arguments. I will get back to this shortly, but for now, you can ignore the <parameters> bit as it is optional. The following program creates a simple function that will print the words Nice Weather! to the Terminal:
def reactToTheWeather(): print("Nice Weather!")
If you run the previous example, you will notice that nothing in particular happens. This is because the code block of a function is ...
Read now
Unlock full access