在整个条件下添加更多等级的括号。这将允许您根据需要插入换行符。
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()
来源
2012-07-30 13:57:28
Kos
只是一个评论,你没有必要在你的例子中有一个'if'语句。你可以'return(self.expires是None或datetime.now()...)' – mgilson 2012-07-30 14:01:33
我刚刚学习Python,我想我可以做到这一点,但没有那么好。谢谢mgilson – kbec 2012-07-30 14:07:21