python中列表推导或生成器表达式的行连续

python中列表推导或生成器表达式的行连续,第1张

python中列表推导生成器表达式的行连续
[x for x in (1,2,3)]

效果很好,因此您几乎可以随心所欲。我个人更喜欢

 [something_that_is_pretty_long  for something_that_is_pretty_long  in somethings_that_are_pretty_long]

不能被很好理解的原因是它出现在一行的 末尾 ,要么不突出,要么需要额外的填充,当行长改变时必须固定它:

x = very_long_term            + even_longer_term_than_the_previous   + a_third_term

在这种情况下,请使用括号

x = (very_long_term     + even_longer_term_than_the_previous     + a_third_term)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5616886.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存