!!! Functions

%%info
This is __Exercise 3__ of the [Micro Python Tutorial].
%%

We can define __functions__ in Python. Functions are defined globally, within the file/module as they begin in ''column 0'' (the left-most position on a line, with no indentation).

A function is a block that defines a series of lines we want to execute when the function is called. We can pass zero or more __arguments__ (variables) to the function.

%%filename main.py %%
%%python
\\# we define a function called "display_message", passing a single argument named "message"
def display_message(message):
    print(message)
    raise Exception('we did something wrong.')

try:

    # we call or execute the function here
    display_message('hello world.')

except Exception as e:
    print('an error occurred: {}'.format(e))
finally:
    print('complete.')
%%

----
__Previous:__ [MicroPython Tutorial Exercise 2|MicroPythonTutorialExercise02]: blocks \\
__Next:__ [MicroPython Tutorial Exercise 4|MicroPythonTutorialExercise04]: classes