Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Built-In and Global Scopes | Scopes
Mastering Python: Closures and Decorators
course content

Conteúdo do Curso

Mastering Python: Closures and Decorators

Mastering Python: Closures and Decorators

1. Scopes
2. Closure
3. Decorators

Built-In and Global Scopes

As mentioned earlier, the global scope is your code's main scope (environment). Every script (.py file) has its global scope.

Note

There is only the built-in scope out of the global scope.

We can use functionality from outer scopes in inner scopes. This means that we can use built-in functionality in the global scope as well as in local scopes, which are nested within the global scope.

Look at the example:

In the example above, the global variable number is used inside the print_number() function local scope.

You can access variables and functions from outer scopes but cannot change them:

You can access the change of a global variable/function using the global keyword:

1. What scope is the main scope of your code?
2. What scope is the Python Tools scope?

What scope is the main scope of your code?

Selecione a resposta correta

What scope is the Python Tools scope?

Selecione a resposta correta

Tudo estava claro?

Seção 1. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt