Comparison of different types does not throw exception

Philipp Weinfurter philipprw at
Fri Jul 13 08:42:44 EDT 2001

On Fri, 13 Jul 2001, Nils O. Selåsdal <noselasd at> wrote:
> "Gordon Williams" <g_will at> wrote in message
>> I would like to know why python does not produce an exception when a
>> comparison of objects of different types is made.  For example:
>> >>> 1 < "aaa"
>> 1
> In any OO language its desired to take advantage og polymorphisme,
> and let comparison between diffrent objects be allowed.The programmer
> is responsible,
> for providing comparison functions.
> I wanna know if my User also equals my SecureUser....

hmm, i'm still new to python, so please correct me if i'm wrong here.
but since you can not subclass `integer' and `string' (and override the 
comparison operators for those types), there is not much polymorphism here.
and as the language reference states:
"Otherwise, objects of different types always compare unequal, and are
ordered consistently but arbitrarily."
i, too, think that this doesn't make much sense.


More information about the Python-list mailing list