Python Scope
Python Tutorial » Python Scope
A variable is only available from inside the region it is created called scope.
Local Scope
A variable created inside a function can only be used inside that function.
Example:
Output: 2021
def my_func():
y = 2021
print(y)
y = 2021
print(y)
myfunc()
Output: 2021
Function Inside Function
Variable y is not available outside the function, but it is available for any function inside the function
Example:
Output:
def my_func_name():
y = 5422
def my_inner_func():
print(y)
my_inner_func()
my_func_name()
y = 5422
def my_inner_func():
print(y)
my_inner_func()
my_func_name()
Output:
Global Keyword
The "global' (without quotes) keyword makes the variable global.In the next program, three different variables "y" are defined in separate namespaces and accessed accordingly.
Example:
Output:
y = 230
y = 230
y = 230
def my_outer_function():
global y
y = 220
def my_inner_function():
global y
y = 230
print('y =', y)
my_inner_function()
print('y =', y)
y = 210
my_outer_function()
print('y =', y)
y = 230
y = 230
y = 230
Python scope : variables, error initializing python engine, could not detect python version, rules, function, of variable in for loop, in future, if, for loop
Python Scope - python
Online Editor
This tool makes it easy to create, adjust, and experiment with custom colors for the web.
HTML Templates

Magnews2 is a modern and creative free magazine and news website template that will help you kick off your online project in style.
CSS HTML Layout

Find here examples of creative and unique website layouts.
Free CSS HTML Menu

Find here examples of creative and unique website CSS HTML menu.