scope of variable

Burton Samograd burton at userful.com
Fri Aug 20 15:19:08 EDT 2010


M B <znarus at telia.com> writes:

> Hi, 
>>>> dept=0
>>>> def mud():
> 	print dept
>
> 	
>>>> mud()
> 0
>>>> def mud():
> 	dept+=1
> 	print dept

You should add a global statement or else python thinks a variable used
is a local:

>>> def mud():
    global dept
 	dept+=1
 	print dept

--
Burton Samograd




More information about the Python-list mailing list