Python โ From Basics to Advanced ยท Functions and Modules
Scope: Local and Global Variables
Functions and Modules
Introduction
Scope means where a name is visible โ who can see it. Variables created inside a function are local and disappear when the function returns. The LEGB rule (Local, Enclosing, Global, Built-in) describes how Python looks up a name. The global and nonlocal keywords let you intentionally modify variables from an outer scope.