Python`如果x不是None`或`if not x is None`? - Python `if x is not None` or `if not x is None`?

07/10 13:56
阅读数 42

问题:

I've always thought of the if not x is None version to be more clear, but Google's style guide and PEP-8 both use if x is not None . 我一直认为if not x is None版本更清楚,但谷歌的风格指南PEP-8都使用, if x is not None Is there any minor performance difference (I'm assuming not), and is there any case where one really doesn't fit (making the other a clear winner for my convention)?* 是否存在任何轻微的性能差异(我假设没有),是否存在任何一个真正不合适的情况(使另一个成为我公约的明显赢家)?*

*I'm referring to any singleton, rather than just None . *我指的是任何单身人士,而不仅仅是None

...to compare singletons like None. ...比较像无的单身人士。 Use is or is not. 使用是否。


解决方案:

参考一: https://stackoom.com/question/BNEq/Python-如果x不是None-或-if-not-x-is-None
参考二: https://oldbug.net/q/BNEq/Python-if-x-is-not-None-or-if-not-x-is-None
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
在线直播报名
返回顶部
顶部