How can I save three double quotes in a Python doctrine?

I have a large ASCII logo that I want to save in a docstring. This logo contains several copies of three double double quotes. The size and complexity are such that escaping individual characters is not a realistic option. Given that in no case is it an instance of three consecutive double quotes in isolation on the line, how can this logo be stored in the dock?

Here is a minimal example:

logo = """
hello"""world
"""

The resulting error is as follows:

    hello"""world
                ^
SyntaxError: invalid syntax
+4
source share
3 answers

Just use single quotes.

logo = '''
hello"""world
'''

If you don't want to break PEP8, you might be a little hacky

logo = """
hello'''world
""".replace("'", '"')
+4

"" PEP8 ''':

logo = '''
       hello"""world
       '''
0

,

>>> """ \"\"\" """
' """ '
>>> 
0

All Articles