Learn Before
Concept

Scope in Python

Scope determines where a variable can be accessed. The two common Scopes are Local scope and Global scope.

Variables in Local scope are called local variables and these variables are defined inside a function. Local variables can only be accessed inside that function. Similarly, variables defined inside a loop of a function can only be accessed inside that loop. To use those variables outside of the loop in the rest of the function, they must be defined before the loop starts.

Variables in Global scope are called global variables and these are defined outside functions. Global variables are accessible anywhere in the Python module.

0

1

Updated 2021-06-24

Tags

Python Programming Language

Data Science