It is essential to understand what names mean in Python. When you use a name in a program, Python creates, changes, or looks up the name in what is known as a namespace, a place where names live. The term “scope” refers to a namespace.
Names in Python begin to exist when they are first assigned values, and they must be assigned before they are used.
All names assigned inside a function are associated with that function’s namespace which means that names assigned inside a
def can only be seen by the code within that
def, they do not clash with variables outside the
def (even if the same names are used; an
a variable inside a
def is different than an
a variable outside the