Lin Ma Lin Ma - 6 months ago 14
Python Question

Python string escape

The content of string is like this, and it has many

"
and many
'
, below is just a simple example, is there a way I can represent such a string as a constant string and assign to a variable without escape
"
and
'
. Just want to save some typing for escape
"
and
'
and make string more readable in code. :)

--pretty-print "http://foo.com" {'bbb'}


BTW: using Python 2.7.

thanks in advance,
Lin

Answer

Use triple quotes, either single or double. You can have multiple lines in triply-quoted strings, but you don't have to.

option = """--pretty-print "http://foo.com" {'bbb'}"""