[Tutor] return class-call or value
Wong Zhee Shiong
zswongg@hotmail.com
Thu Dec 19 21:27:01 2002
Hi all,
Below is a common class example found in textbooks.
>>>class P:
... def __init__(self, p1, p2):
... self.dat=(p1,p2)
... def __add__(self,other):
... return self.__class__(self.dat[0] + other.dat[0], \
... self.dat[1] + other.dat[1])
... # or perhaps "return P(...)"
...
If I replace the return statement with a value, i.e.
return (self.dat[0] + other.dat[0], self.dat[1] + other.dat[1])
I still get the same result for >>> p = P(1,1) as before replacement, but
what do I miss (wrong) about returning a value in OOP sense?
Thanks,
wong
_________________________________________________________________
The new MSN 8: smart spam protection and 3 months FREE*.
http://join.msn.com/?page=features/junkmail&xAPID=42&PS=47575&PI=7324&DI=7474&SU=
http://www.hotmail.msn.com/cgi-bin/getmsg&HL=1216hotmailtaglines_smartspamprotection_3mf