Variable Scope in python
# Global varible is used in all of the program and used all functions from the program
m = 23
n = 20 # Global variable
def function1(n):
# n = 40 # Local variable
# print(n,"Hello this is not Golbal variabel")
# return n
# define a variable as a global variable
global m # have more prority then the variable out side the function
m = 43
print(m)
print(n, "hello love you hogia")
# we can't access local variable out side the function
function1("this is great")
print(m)
Comments
Post a Comment