Review of terms#

Terminology of functions and scopes can be confusing, because there are many different terms commonly used for the same or almost the same concept … even in the Python documentation.

Scope, namespace, frame, symbol table#

A namespace may also be called a symbol table or a frame.
These terms are not quite identical (a frame is really a structure inside the Python interpreter used to implement a namespace), but they are so closely related that you can treat them as synonyms.

The term scope is also almost interchangeable with namespace, except “local scope” means “the namespace of the currently executing function.” There is always exactly one “local” scope and one “global” scope, while there may be many namespaces that are temporarily inaccessible.

Every frame implements a namespace, which may be the local scope or global scope. Outside of any function, the local scope and the global scope may be the same namespace.

The technical distinctions may matter to you someday if you build your own programming language interpreter.
For now you can treat namespace, scope, and frame as synonyms.

Local and global variables#

A local variable is a variable in the namespace (scope) of a function, accessible only when that function is executing. A global variable is a variable defined in the global namespace, which may also be accessible from within functions.

Formal and actual arguments (parameters)#

The terms parameter (formal parameter or actual parameter) and argument (formal argument or actual argument) are synonymous. The author of this chapter looked to the Python documentation to see which term was standard in Python. The disappointing answer was “both”.

It could be confusing to pair “formal parameter” with “actual argument”, so we will try to be consistent in preferring “argument” in both contexts. Occasionally we will use both terms, since you will often encounter “formal parameter” in other documentation.
Sometimes we will mess up … let us know so we can fix inconsistencies in this text.

When we use the term argument in the context of defining a function, we mean formal argument, that is, the name that will be used within the function body. When we use the term argument in the context of calling a function, we mean actual argument, that is, the value transmitted to the function.

def f(a):  # a is a formal argument
    """Does nothing"""
    pass

f(x)      # x is an actual argument