Global Variables
Sean Ross
sross at connectmail.carleton.ca
Wed May 7 11:32:50 EDT 2003
>>> x = 10
>>> print x
10
>>> def modify():
... global x
... x = 20
...
>>> modify()
>>> print x
20
>>>
"DD" <qyu2 at nortelnetworks.com> wrote in message
news:b9b7ee$15l$1 at zcars0v6.ca.nortel.com...
> I have a question regarding the use of global variables in python.
>
> Will the value of a global variable in the execute method of a class,
revert
> back to the original value prior to entering the method.
>
> For example:
>
> global variable x=10
>
> Now we enter the execute method of a class
> global x
> now we modify x=20 in this method
> return
> Can we return x=20 outside of this method? It appears x=10 always. So
the
> global variable x in this method is not updated to reflect the fact it has
> been changed in the method. How do I return with the value x=20?
>
> Thanks for any help.
>
>
>
More information about the Python-list
mailing list