How does Python's triple-quote string work?

后端 未结 9 1094
野性不改
野性不改 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:35

    Subsequent strings are concatenated, so you can use:

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

    This will allow you to keep indention as you like.

提交回复
热议问题