In this example we will show how to make local variables global using the global keyword in Python.
Source Code
def my_func():
global var1 # make the variable global
var1 = 5
print(var1)
my_func()
print(var1)
Output:
5
5
In this example we will show how to make local variables global using the global keyword in Python.
def my_func():
global var1 # make the variable global
var1 = 5
print(var1)
my_func()
print(var1)
Output:
5
5