Python style: multiple-line conditions in IFs
Posted
by
Eli Bendersky
on Stack Overflow
See other posts from Stack Overflow
or by Eli Bendersky
Published on 2008-10-08T06:19:07Z
Indexed on
2011/01/14
10:53 UTC
Read the original article
Hit count: 253
Hello,
Sometimes I break long conditions in IFs to several lines. The most obvious way to do this is:
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.
Edit:
By the way, for the moment I'm using:
if ( cond1 == 'val1' and cond2 == 'val2' and
cond3 == 'val3' and cond4 == 'val4'):
do_something
Not very pretty, I know :-)
Can you recommend an alternative way ?
© Stack Overflow or respective owner