Functions (Python Basics 2)

Functions in Python

  • multiple functions can be defined in any python module/script
    • do not need to be in a separate file
  • functions can have multiple outputs
  • optional arguments and default values are very clean and easy

Defining Functions

Code for the function:

def myfunc(A, B):
    C = A + B
    D = A * B
    return C, D

Using the function:

x, y = myfunc(4, 5)
  • Note: functions can be placed directly in a Python file or imported from other modules.