与无比较 [英] comparison with None

查看:43
本文介绍了与无比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

>>无> = 0

错误


>>无< = 0



True


说明赞赏。


谢谢,

Alan Isaac

解决方案



" Alan G Isaac" < ai **** @ american.eduwrote in message

news:3I ************************** **** @ rcn.net ...

| >>无> = 0

|错误

| >>无< = 0

|真的

|

|感谢解释。


应该在比较的参考手册部分。


Alan G Isaac写道:


>>无> = 0



False


>>无< = 0



True


说明赞赏。


谢谢,

Alan Isaac



我读过并发现''无'比较并不总是一个好主意。

更好to:

from types import NoneType


x = None

如果type(x)== NoneType:

#true

<代码>

else:

#false;做其他事情。

<更多代码>


Steven Howe


4月18日下午5:19,Steven Howe< howe.ste ... @ gmail.comwrote:


Alan G Isaac写道:


>>无> = 0



错误


> >无< = 0



True


说明赞赏。


谢谢,

Alan Isaac



我'已经阅读并发现''无'比较并不总是一个好主意。

最好:

来自类型进口NoneType


x =无

如果类型(x)== NoneType:

#true

<代码>

else:

#false;做其他事情。

<更多代码>


Steven Howe



没有单身 - 只有一个没有,没有其他。与None无关的唯一

比较是是。或不是。 type(x)

== NoneType是不必要的,x是None就足够了。


>> x =无
x为无



True
< blockquote class =post_quotes>


>> y =无
x是y



True


> > z = object()
z是无



False


>> z不是无



True


>> x不是无



False


>> y不是无



False


- Paul


>>None >= 0
False

>>None <= 0

True

Explanation appreciated.

Thanks,
Alan Isaac

解决方案


"Alan G Isaac" <ai****@american.eduwrote in message
news:3I******************************@rcn.net...
| >>None >= 0
| False
| >>None <= 0
| True
|
| Explanation appreciated.

Should be in the reference manual section on comparisons.


Alan G Isaac wrote:

>>None >= 0

False

>>None <= 0

True

Explanation appreciated.

Thanks,
Alan Isaac

I''ve read and found that ''None'' comparisons is not always a good idea.
Better to:
from types import NoneType

x = None
if type( x ) == NoneType:
# true
< code >
else:
# false; do something else.
< more code >

Steven Howe


On Apr 18, 5:19 pm, Steven Howe <howe.ste...@gmail.comwrote:

Alan G Isaac wrote:

>>None >= 0

False

>>None <= 0

True

Explanation appreciated.

Thanks,
Alan Isaac


I''ve read and found that ''None'' comparisons is not always a good idea.
Better to:
from types import NoneType

x = None
if type( x ) == NoneType:
# true
< code >
else:
# false; do something else.
< more code >

Steven Howe

None is a singleton - there is but one None and no other. The only
comparisons that make sense with None are "is" or "is not". type(x)
== NoneType is unnecessary, x is None is sufficient.

>>x = None
x is None

True

>>y = None
x is y

True

>>z = object()
z is None

False

>>z is not None

True

>>x is not None

False

>>y is not None

False

-- Paul


这篇关于与无比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆