Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53006 > unrolled thread

Python Global variable

Started bychandan kumar <chandan_psr@yahoo.co.in>
First post2013-08-26 17:54 +0800
Last post2013-08-26 17:54 +0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Python Global variable chandan kumar <chandan_psr@yahoo.co.in> - 2013-08-26 17:54 +0800

#53006 — Python Global variable

Fromchandan kumar <chandan_psr@yahoo.co.in>
Date2013-08-26 17:54 +0800
SubjectPython Global variable
Message-ID<mailman.239.1377532327.19984.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web