On Fri, May 4, 2012 at 10:12 AM, Dave Angel <[email protected]> wrote: > On 05/04/2012 09:29 AM, Lion Chen wrote: >> Hi, All, >> here are the codes: >> >> class a: >> pass >> >> >> i = a () >> j = a () >> k = a () >> >> i < j returns True >> >> j < k returns False >> >> why? >> >> Lion Chen >> _______________________________________________ >> Tutor maillist - [email protected] >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > i, j and k are three distinct instances of the class a (which should be > capitalized for clarity). > > Since you don't supply any comparison operator special methods in your > class, Python 2 simply compares their id values. So the ordering is > entirely undefined, and each of us might get different results. I, for > example, got true and true. > > In Python 3, you'd get the following error, which is an improvement, imho: > > TypeError: unorderable types: A() < A() > > > > > -- > > DaveA > > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor
One more thing. The reason the L is printed in the python interactive shell is because it is showing the repr() of the variable. Whe -- Joel Goldstick _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
