String contain double quote? How to do? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

String contain double quote? How to do?

15th Apr 2017, 12:42 PM
AidilSha 6
AidilSha 6 - avatar
4 Answers
+ 11
myString = "my string is awesome"
15th Apr 2017, 12:58 PM
Gami
Gami - avatar
+ 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 :)
15th Apr 2017, 2:32 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
you should use escape sequence for example m="\"hello\""
17th Apr 2017, 6:22 AM
Harshitha P N
+ 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 !
20th Apr 2017, 6:49 PM
SATYAJEET JHA
SATYAJEET JHA - avatar