更新时间:2022-11-07 23:29:14
如果您的理解力太长,可以使用@brandizzi提到的 \
来打破它,但是我认为您可能会只需在有意义的地方使用理解并在不知道的地方扩展到常规代码,便会更好:
If you have a comprehension that is too long you can break it with \
as @brandizzi mentions, but I think you might have better luck just using comprehensions where they make sense and expanding to 'regular' code where they don't:
alert x for x in [1,2,3,4,5] when x > 2
...可以重写为...
...can be rewritten as...
for x in [1,2,3,4,5]
alert x if x > 2
...甚至...
for x in [1,2,3,4,5]
if x > 2
alert x
换句话说,理解力是简短,简洁的摘要的语法糖-您不必将它们用于所有操作。
In other words, comprehensions are syntactic sugar for short, concise snippets - you don't have to use them for everything.