Python 附加到此处引用的三重文件

Python 附加到此处引用的三重文件,python,Python,我有一个heredoc,它的最后一行相当长,所以我想在其中加一个换行符,以便在源代码中很好地格式化,但是。。。我看到一些不同的行为取决于上下文。这是有道理的,但也是不完美的。在以下两种情况下,我是否可以使用一些分组运算符来保持它们在行为上的等效性?[注意,您不能轻松地将其输入到REPL中,因此这暗示我需要某种分组] $ python -c 'print(""" > hello > world > """ > "Addendum: Long " > "Line Her

我有一个heredoc,它的最后一行相当长,所以我想在其中加一个换行符,以便在源代码中很好地格式化,但是。。。我看到一些不同的行为取决于上下文。这是有道理的,但也是不完美的。在以下两种情况下,我是否可以使用一些分组运算符来保持它们在行为上的等效性?[注意,您不能轻松地将其输入到REPL中,因此这暗示我需要某种分组]

$ python -c 'print("""
> hello
> world
> """
> "Addendum: Long "
> "Line Here Is Broken Yet Continued."
> )'

hello
world
Addendum: Long Line Here Is Broken Yet Continued.
$ python -c 's="""
hello
world
"""
"Addendum: Long "
"Line Here Is Broken Yet Continued."
print(s)'

hello
world

最后一个是将两个额外的字符串作为它们自己的有效无运算语句。

在第一个示例中使用的分组运算符是括号

$ python -c 's=("""
hello
world
"""
"Addendum: Long "
"Line Here Is Broken Yet Continued.")
print(s)'

hello
world
Addendum: Long Line Here Is Broken Yet Continued.

在第一个示例中使用了分组运算符,它是括号

$ python -c 's=("""
hello
world
"""
"Addendum: Long "
"Line Here Is Broken Yet Continued.")
print(s)'

hello
world
Addendum: Long Line Here Is Broken Yet Continued.

在Python 2中,print()的参数是可选的。因为在Python3中,它们并不像print()是一个方法,我并没有把它看作分组,而是调用。谢谢。在Python 2中,print()的参数是可选的。因为在Python3中,它们并不像print()是一个方法,我并没有把它看作分组,而是调用。谢谢