Mik*_*Lin 30 python python-2.x
在Python中,None评估小于零?
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> None < 0
True
>>> None == 0
False
>>> None > 0
False
>>>
Run Code Online (Sandbox Code Playgroud)
这是预期的吗?
我猜想这None将等于零(通过类型强制),或者所有这些语句都会返回False.
从文档:
CPython实现细节:除数字外的不同类型的对象按类型名称排序;不支持正确比较的相同类型的对象按其地址排序。
NoneType比较为小于,int因为比较似乎区分大小写。
>>> type(0)
<type 'int'>
>>> type(None)
<type 'NoneType'>
>>> 'NoneType' < 'int'
True
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15607 次 |
| 最近记录: |