Scopes

What is a Scope?

A scope in Python is where named objects, such as classes, variables and functions, are kept.

Local Scope

What is the Local Scope?

The local scope is the current active scope. If you create a function, a new scope will be created with it and assigned to it. Any named objects created inside of it, will belong to it and won't be accessible from another scope.

Global Scope

What is the Global Scope?

The global scope is a scope like any other, except, it can be accessed from any other scope. If you needed to create a variable in one function but use it in another, one way to use it from the other function, would be to, in the first function, make it a global variable.

Last updated