Variable Scope in python

 # Global varible is used in all of the program and used all functions from the program


= 23
= 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