Global variables – The variable whose value is accessible from any block is called Global variable.
The Scope of the global variable is the entire program. Whatever the variables we are declaring upon the user defined function is known as the global variable.
a= 20 def funct(): global a print(a) funct() print(a)
Output- 20 20
Local variable– The variable which is defined and accessed in a particular block and cannot be accessed outside that block is known as Local variable.
The scope of the local variable is within the function where the variable is declared. Whatever the variable is declared inside the user defined function is known as the local variable.
def difference(x, y): difference = x - y return difference print(difference(10,3))
This is all about global and local variable in python.