Function

A function, or subroutine, is a sequence of program instructions that performs a specific task, packaged as a unit.

Arguments (parameters) are passed in to functions by reference:

  • the reference variable points to a value that already exists in memory rather than a copy of that variable

  • any changes made to the variable from inside the function will actually be made in the actual variable outside the function

Python Example

# Define a function with its signature.
def my_function(parameter1, parameter2):
    
    # Define statements the use the function parameters.
    print(str(parameter1), str(parameter2))
 
    # Return from the function
    return

# Use the function.
my_function(1, "a")