How does Python's triple-quote string work?

后端 未结 9 1101
野性不改
野性不改 2020-12-09 08:09

How should this function be changed to return \"123456\"?

def f():
    s = \"\"\"123
    456\"\"\"
    return s

UPDATE: Everyo

9条回答
  •  旧巷少年郎
    2020-12-09 08:30

    textwrap.dedent("""\
                    123
                    456""")
    

    From the standard library. First "\" is necessary because this function works by removing the common leading whitespace.

提交回复
热议问题