Variable in python | local and global variables in python

technical talkiess
0

 # global variable 



l = 6 # global variable 


def globalandlocal(n):

# l = 9 #local variable.... function always get local variable value 

    

   # if you want to change global varaiable value simple put global keywork before varaible then you can change it otherwise not change the value .... example below 

   

    global l

    l = l+1

    print(n + " is the best person")

    print(l)



def func1():

    x = 10

    def funct2():

        x = 20

    print("Before calling function " , x)

    funct2()

    print("After calling function :- " , x)


    # in this case it's print 10 because no global varaible avaialble that's why the local variable is print 


globalandlocal("Vishal")

func1()

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)