开发者

python: how to set a string equal quotes?

i have quotes inside a开发者_运维知识库 string like this

string1="blah blah blah "  some'  thi'ng "  end of string "

how do i make sure the quotes are included in there?

please note i have both doubel and single quotes in there


Triple quotes are harder to break.

string1="""blah blah blah "  some'  thi'ng "  end of string """


You can use \" to make quotes not break quotes.


if you don't want to go through the whole string putting a backslash before every offending quote, i'd enclose the string in triple quotes. this is especially good for a string that will span several lines.


You can use \" for using double quotes within double quoted string.

string1 = "blah blah blah \"  some'  thi'ng \"  end of string "

OR you can use ' single quotes for declaring string:

string1 = 'blah blah blah \"  some'  thi'ng \"  end of string '

OR you can use """ triple quotes for string declaration:

string1 = """blah blah blah \"  some'  thi'ng \"  end of string """

Refer article about String Literals for getting complete list of escape sequences

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜