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 - Tutor@python.org > 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 - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor