Defining a function in Python is easy! In your text editor, a simple count-up python function may look like this (to the right is the exact same function written in snap):

Function Header: Like in snap, the function header specifies the name of the function, and any arguments (inputs, or parameters) into the function. Notice the line must begin with the keyword def and end with a :. This lets the interpreter know that the indented lines that follow are part of a function definition.

In snap it's common to have text between function parameters, such as the Snap! mod block. In Python, all parameters must come at the end of a function, between ().

For Loop: The for loop in Python works similarly to our snap for loop with some key differences. To have the index variable i increment from 1 to num, we have to create an iterable. An iterable is a just list of items. Starting with the first item, i takes each consecutive item of the list as its value. The range(x, y) function receives two numbers and returns a list of all numbers beginning with x and ending with y-1.


>>> list(range(2, 6))
[2, 3, 4, 5]
            

NOTE: The list returned by range(x,y) does NOT include y.