To know about local & global variables in python3.
It should be declared within the function.
We can use local variables within their scope only.
It should be declare outside the function.
If it is declare within the function use global keyword at the start of the declaration.
Once made change in global variable the entire program will be change.
We can use global variable anywhere in the program.
#declare a global variable
y = 5
#declare a global variable
with in function
#declare a local variable a
def func1(a):
global z
z = 3
return a*z
#declare another function
with local variable x
def func2(x):
return x*y
#method call using
positional arguments
total = func1(3)
total1 = func2(4)
print(“\n”)
#print the result
(“multiplication of local and global variable is:”,total)
print(“\n”)
(“multiplication of local and global variable is:”,total1)