在Python2中,不同类型对象的默认比较是使用id它们的类型(通过将对象指针转换为整数获得)。这里是来源的链接:http://hg.python.org/cpython/file/2.7/Objects/object.c#l757 http://hg.python.org/cpython/file/2.7/Objects/object.c#l757
在我的构建中,以下是类型的排序:
>>> sorted([bool, int, float, long, list, tuple, dict, str, unicode])
[<type 'bool'>, <type 'float'>, <type 'int'>, <type 'list'>, <type 'long'>,
<type 'dict'>, <type 'str'>, <type 'tuple'>, <type 'unicode'>]
数字(复数除外)具有允许基于数值进行交叉类型比较的比较方法(即浮点数可以与整数进行比较)。
The None对象很特殊。它比其他一切都少。
要查看所有内容的组合,请使用sorted查看订单:
>>> sorted(zoo)
[None, -5, -5.0, 0, 0.0, -0.0, False, True, 10, 10.0, 11.5, {},
{'abc': 10}, {'lmno': 20}, [], [1, 2], [1, 2, 3], [1, [2, 3]],
'', u'', 'alpha', u'alpha', 'bingo', 'cat', (), (1, 2),
(1, 2, 3), (1, (2, 3)), u'bingo', u'cat']