+ 1
String contain double quote? How to do?
4 ответов
+ 11
myString = "my string is awesome"
+ 6
if your string contains double quotes like:
"oh, my dear!" - she replied
and you want to store it with those quotes, you may either go with using single quotes as string definition:
reply = '"oh, my dear!" - she replied'
or escape those double quotes:
reply = "\"oh, my dear!\" - she replied"
This second method can be inevitable if the string contains both single and double quotes :)
+ 4
you should use escape sequence
for example m="\"hello\""
+ 1
you can use the escape sequence to avoid accidental removal of these single/double quotes. For Ex. if you want to print "Hello there". you can do it as follows :
print("\"Hello there\"") or you can enclose your entire string within single quotes as suggested by 'Kuba'.
Hope that helps.
Happy coding !