考虑以下代码:
if (something1 is not None and
check_property(something_else) and
dr_jekyll is mr_hyde):
do_something(*args)
other_statements()
尽管代码是以PEP-8的方式编写的,但很明显很难判断谓词的结束和主体的语句的开始。你知道吗
我们设计了两种变体:
if ((something1 is not None) and
(check_property(something_else)) and
(dr_jekyll is mr_hyde)):
do_something(*args)
other_statements()
这是丑陋和
if (something1 is not None and
check_property(something_else) and
dr_jekyll is mr_hyde):
do_something(*args)
other_statements()
这也很难看。你知道吗
我个人更喜欢1,我的同事用2。是否有一个非丑陋的和PEP-8兼容的规范解决方案,可以提高上述方法的可读性?你知道吗
使用all()更改if语句:
根据您的上下文,您可能不需要
is not None
相关问题 更多 >
编程相关推荐