scope of variable

M B znarus at telia.com
Fri Aug 20 14:09:36 EDT 2010


Hi, 
I try to learn python.
I don't understand this:

(running in idle)

>>> dept=0
>>> def mud():
	print dept

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

	
>>> mud()
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    mud()
  File "<pyshell#6>", line 2, in mud
    dept+=1
UnboundLocalError: local variable 'dept' referenced before assignment
>>> 

Regards MB




More information about the Python-list mailing list