Functions



Python Function Syntax



def function_name(arg_1, arg_2):
    statements...
    return value


• A function name
◇ Cannot start with a number [0-9]
◇ Cannot conflict with a language keyword
◇ Can contain: [A-Za-z0-9_-]

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Examples



def add(num1, num2):
    result = num1 + num2
    return result

>>> add(35)
8


• A function doesn't have to have any arguments or return any values

>>> def say_hello():
        print("Hello!")

>>> say_hello()
Hello!

Index