FAQ: Introduction to Functions - Multiple Parameters

Please view How do I format code in my posts? as without it code loses formatting and more importantly indentation.

Make sure any statements that are part of your function are indented to the same level as the function, especially if they use function local names that are forgotten once the function has finished executing.

For example the following perfectly valid-

def func():
    x = 3
    print(x + 2)
    return x

Out: 3

Whereas this will fail because there is no x in the outer scope (the x is local to the function, the function itself is denoted by its indentation and print is back in the outer scope).

def func():
    x = 3

print(x)  # ERROR
1 Like