python中的新代码行

时间:2014-06-11 11:26:04

标签: python

我正在做一些Python编程,我有几行超过120个字符,这是我们编码风格指南中的最大线宽。

现在我想知道如何在python中进行换行,这是一个例子:

someString = "Here is a [.......] very long text"    # This line is now 130 chars long

我想要这样的事情:

someString = "Here is a [...]
    [...] very long text"

如何像这样格式化我的python脚本?

2 个答案:

答案 0 :(得分:1)

someString = "Here is a [...] \
    [...] very long text"

print('Here is a [...]'
      '[...] very long text')

甚至

someString = ('Here is a [...]'
              '[...] very long string')

或者为什么不

someString = 'Here is a [...]'
someString += '[...] very long string'

答案 1 :(得分:0)

将它放在括号中并用开括号和引号分隔这些行 - 它们会自动连接。

someString = ("Here is a [...]"
              "[...] very long text")