【发布时间】:2020-07-25 23:28:50
【问题描述】:
如何将下面的长行分成两行,以符合PEP8?
percentage = f"{state[0] / state[1] * 100:{3 + (decimals > 0) + decimals}.{decimals}f}%"
注意: 这里的 f 字符串不能像previously asked question 接受的答案中所建议的那样简单地分成两个 f 字符串,因为这会破坏格式。因此,这里的这个问题需要一个不同的更通用的解决方案。
【问题讨论】:
-
只需在“=”之后添加新行 ->
percentage = \ f"{state[0] / state[1] * 100:{3 + (decimals > 0) + decimals}.{decimals}f}" -
如果您担心 88 个字符行上的 PEP8,只需计算上面一行中 f 字符串内的任何内容。请记住a foolish consistency is the hobgoblin of little minds。
标签: python split pep8 f-string