简体   繁体   English

蟒蛇:如何设置一个字符串等于引号?

[英]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 请注意,我在其中同时有doubel和单引号

三重引号更难破解。

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

您可以使用\\"进行引号而不是引号。

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 请参阅有关字符串文字的文章,以获取escape sequences完整列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM