Functions#

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.

main.py

# 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: blocks
Next: MicroPython Tutorial Exercise 4: classes