Question about classes
Ben
reply at to-the-newsgroup.com
Mon Nov 22 11:42:17 EST 2004
On Mon, 22 Nov 2004 06:39:53 +0000, Steven Bethard wrote:
> If instead, you intended to set an instance variable, you might write it
> like:
>
> >>> class C(object):
> ... def __init__(self, x):
> ... if x != 0:
> ... self.x = x
> ... else:
> ... self.x = 5
> ...
> >>> c = C(0)
> >>> c.x
> 5
> >>> c = C(8)
> >>> c.x
> 8
Steve,
That's exactly what I wanted. Thank you very much. I'll keep the class one
in mind too.
--Ben
--Ben
More information about the Python-list
mailing list