gpt4 book ai didi

python - 为什么不同类型的 Python 对象按类型名称排序?

转载 作者:行者123 更新时间:2023-11-28 21:30:57 25 4
gpt4 key购买 nike

来自 Python 文档: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.

有什么理由选择这样做而不是引发异常?

最佳答案

从您引用的那一行开始大约有四行:

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).

您不想在对不同类型的对象列表进行排序时引发异常。

关于python - 为什么不同类型的 Python 对象按类型名称排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/649191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com