tags:

views:

86

answers:

2

From Python docs: http://docs.python.org/library/stdtypes.html#comparisons

Implementation note: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.

Is there any reason for choosing to do this over raising an exception?

A: 

It can be useful for objects of different types to be collected into a single, sorted list, in a definite order. By giving all objects a stable sort order, this behavior is default.

TokenMacGuy
+5  A: 

About four lines up from that line you quoted:

Objects of different types, except different numeric types and different string types, never compare equal; such objects are ordered consistently but arbitrarily (so that sorting a heterogeneous array yields a consistent result).

You don't want to raise exceptions when sorting a list of differently typed objects.

Ali A
Do note that Python 3.x *will* raise an exception when comparing different non-coercible types.
Ignacio Vazquez-Abrams