Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiline string containing """ (triple quotes)

How can I define python multi line string containing """ (3 double quotes)

my desired output is

"""
TEST
"""

Reason: I am writing a script to create some boilerplate code.

like image 937
forvaidya Avatar asked Jan 22 '26 02:01

forvaidya


2 Answers

Use triple single quotes:

'''
"""Test"""
'''
like image 101
BrenBarn Avatar answered Jan 24 '26 22:01

BrenBarn


The solution with ''' should work, but just for the case you need both of them in a string, you can predefine a string with one of them, such as

TRIPSING = "'''"
TRIPDOUB = '"""'

and then

MYSTRING = TRIPDOUB + "\nTEST\n" + TRIPDOUB
like image 31
glglgl Avatar answered Jan 24 '26 23:01

glglgl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!