Sometimes I break long conditions in if
s onto several lines.
(有时我将if
的长条条件分成几行。)
(最明显的方法是:)
if (cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
Isn't very very appealing visually, because the action blends with the conditions.
(在视觉上不是很吸引人,因为动作与条件融为一体。)
However, it is the natural way using correct Python indentation of 4 spaces.(但是,这是使用正确的4个空格的Python缩进的自然方法。)
For the moment I'm using:
(目前,我正在使用:)
if ( cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
But this isn't very pretty.
(但这不是很漂亮。)
:-)(:-))
Can you recommend an alternative way?
(您能推荐一种替代方法吗?)
ask by Eli Bendersky translate from so