Python Scoping: Run it over me one more time please...

Moshe Zadka moshez at math.huji.ac.il
Sat Mar 25 05:10:59 EST 2000


On Fri, 24 Mar 2000, Warren Postma wrote:

> # so how do I create a function that increments a global and returns it!?

Use the (surprise!) "global" keyword:

z = 1
def inc_z():
	global z
	z = z+1
	return z

--
Moshe Zadka <mzadka at geocities.com>. 
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list