Re: Assigning to global variables from within a function
by Tom Plunket other posts by this author
Jul 12 2003 8:49PM messages near this date
Re: Assigning to global variables from within a function
|
Re: Assigning to global variables from within a function
Psymaster wrote:
> I want to do this:
>
> int= 0
>
> def change_int():
> int += 1
>
> change_int()
You shouldn't do that, 'int' is a built-in name. Additionally,
you need to tell the function that the variable is a global one.
my_int = 0
def change_int():
global my_int
my_int += 1
change_int()
You'll find that it works fine.
-tom!
--
http://mail.python.org/mailman/listinfo/python-list
Thread:
Psymaster
Irmen de Jong
Psymaster
Tom Plunket
W Isaac Carroll
|