Class level variables in Python

Brian Munroe bmunroe at
Thu Aug 28 01:43:03 CEST 2003

I am just starting to learn the OO side of Python scripting, and I am
a little confused on the following.  Take the following example class:

>>> class rectangle(object):
	z = 1
	def __init__(self):
		self.x = 2

>>> r = rectangle()
>>> print r.z
>>> print r.x
>>> r.z = 16
>>> print r.z
>>> r.x = 17
>>> print r.x

I was wondering if someone could explain if there is any difference
between initalizing your object attributes up in the __init__
constructor or setting them up as (I am guessing at the name here)
object level variables (like z)


-- brian

More information about the Python-list mailing list