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

微笑、不失礼 提交于 2020-08-05 12:30:56

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!