top of page

Mission 1.6 - Functions and Returns

​

A function is a block of reusable code that is used to perform a single related action. Python comes with many built in functions such as print(), but you can also create your own.

 

Construct a function:

  • Define the function using the Python keyword def. After the word def, give the function a name followed by parentheses and a colon. For example, the following would be a simple function definition

def my_function():

To call a function:

Defining a function is just that: defining it. In order to actually get the code to execute, you must call the function. You can call a function from another function or directly from the Python prompt. To call the example function we just discussed, you would type the function name and parentheses within another function or from the command line

 

Parameters:

A parameter is information that is passed into the function to be used later within the function. You can have as many parameters are you want and they can be of any type

bottom of page