Note that this site is in currently in version 1.0.0-alpha.   Some functionality may be limited.


Functions are ways of doing things in Python. They take some input and do something with it, and can return a value. For example, a function can return the results of a calculation. If your function takes an argument, it will go inside the parentheses. Functions are first defined then called to be executed. This allows you to first write the function but only call it (execute its code) when you need to in Python. Example:

def multiply(a, b):
    result = a * b
multiply(2, 3)

The first code block defines the function multiply() which takes a & b as arguments. The function sets result to the caluclation of a x b. It then returns the value of result. Finally, the function is called with arguments 2 & 3, which will be substituted for a and b in the function definition.


More in-depth exploration of functions on Programiz.


Simple walk-through of functions on w3schools.

Lessons referring to this term