How does Python's triple-quote string work?

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

    Maybe I'm missing something obvious but what about this:

    def f():
        s = """123456"""
        return s
    

    or simply this:

    def f():
        s = "123456"
        return s
    

    or even simpler:

    def f():
        return "123456"
    

    If that doesn't answer your question, then please clarify what the question is about.

提交回复
热议问题