[Tutor] class question
Frank Holmes
flash1210@hotmail.com
Wed, 30 Jan 2002 22:49:47 -0800
I have a question concerning one of the class examples given in O'Reilly's
book "Learning Python"
the following example is given:
>>>class adder:
def __init__(self, value=0):
self.data=value #initialize data
def __add__(self, other):
self.data=self.data + other #add other in-place
def __repr__(self):
return `self.data` #convert to string
...
...
>>>x=adder(1) #__init__
>>>x=2; x=2 #__add__
>>>x #__repr__
5
I am not understanding this at all. In assigning x=adder(1), self.data is
given the value 1, right?
x+2; x+2 should = 1+2; 1+2 ???
I am missing the point completely..... help
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.