在整个条件周围添加额外级别的括号。这将允许您根据需要插入换行符。
if (1+1==2
and 2 < 5 < 7
and 2 != 3):
print 'yay'
关于实际使用的空格数,Python Style Guide没有任何规定,但给出了一些想法:
# No extra indentation.
if (this_is_one_thing and
that_is_another_thing):
do_something()
# Add a comment, which will provide some distinction in editors
# supporting syntax highlighting.
if (this_is_one_thing and
that_is_another_thing):
# Since both conditions are true, we can frobnicate.
do_something()
# Add some extra indentation on the conditional continuation line.
if (this_is_one_thing
and that_is_another_thing):
do_something()