网站名称要注册吗,vs做网站不用建项目,建站的方式有哪些,怎么下载1688上的视频使用 if x is not None 还是if not x is None呢#xff1f;
谷歌的风格指南和PEP-8都使用if x is not None#xff0c;那么它们之间是否存在某种轻微的性能差异呢#xff1f;通过测试发现没有性能差异#xff0c;因为它们编译为相同的字节码#xff1a;Python 2.6.2 (r262…使用 if x is not None 还是if not x is None呢
谷歌的风格指南和PEP-8都使用if x is not None那么它们之间是否存在某种轻微的性能差异呢通过测试发现没有性能差异因为它们编译为相同的字节码Python 2.6.2 (r262:71600, Apr 15 2009, 07:20:39) import dis def f(x):... return x is not None... dis.dis(f)
2 0 LOAD_FAST 0 (x)
3 LOAD_CONST 0 (None)
6 COMPARE_OP 9 (is not)
9 RETURN_VALUE def g(x):... return not x is None... dis.dis(g)
2 0 LOAD_FAST 0 (x)
3 LOAD_CONST 0 (None)
6 COMPARE_OP 9 (is not)
9 RETURN_VALUE
但是在使用风格上尽量避免not x is y。尽管编译器总是将其视为not (x is y)但读者可能会误解构造为(not x) is y。所以if x is not y就没有这些歧义。
以上就是使用 if x is not None 还是if not x is None的详细内容更多请关注php中文网其它相关文章本文原创发布php中文网转载请注明出处感谢您的尊重