ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

python – 一切都比无?

2019-09-17 22:06:19  阅读:212  来源: 互联网

标签:python-datamodel python python-3-x


参见英文答案 > A number smaller than negative infinity in python?                                    1个
除了None之外,是否有Python内置数据类型,其中:

>>> not foo > None
True

其中foo是该类型的值? Python 3怎么样?

解决方法:

None总是小于Python 2中的任何数据类型(参见object.c).

在Python 3中,这已经改变了;现在在没有合理的自然排序的情况下对事物进行比较会导致TypeError.从3.0 “what’s new” updates开始:

Python 3.0 has simplified the rules for ordering comparisons:

The ordering comparison operators (<, <=, >=, >) raise a TypeError exception when the operands don’t have a meaningful natural ordering. Thus, expressions like: 1 < '', 0 > None or len <= len are no longer valid, and e.g. None < None raises TypeError instead of returning False. A corollary is that sorting a heterogeneous list no longer makes sense – all the elements must be comparable to each other. Note that this does not apply to the == and != operators: objects of different incomparable types always compare unequal to each other.

这会使一些人感到不安,因为它通常很方便地执行诸如对其中包含一些None值的列表进行排序,并使None值在开头或结尾处聚集在一起. There was a thread on the mailing list about this不久前,但最终的一点是Python 3试图避免做出关于排序的任意决定(这在Python 2中发生了很多).

标签:python-datamodel,python,python-3-x
来源: https://codeday.me/bug/20190917/1810082.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有