Python Global variable

C

chandan kumar

Hi all,

Please see the below code,in which i'm verifying the global value in python..

CHK=10

def test1():
print "Value of CHK in test1",CHK

def test2():
CHK=40
print "Value of CHK in test2",CHK
test1()

def test3():
global CHK
test2()

test3()

When i ran above code ,I'm getting vlaue of CHK as 40 in test2 method and 10 in test1 method
Can somone explain me why the value of CHK is different in method test1 and test2.

Best Regards,
Chandan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top