Create a string containing a double quote | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson

Create a string containing a double quote

20th Feb 2017, 6:57 AM
deepu c
deepu c - avatar
3 Answers
+ 2
If you have to use single / double quotes in a string, just use the type of quotes that are NOT used in the string. For example: singleQuoteInside = "'Single quotes are a part of string so double quotes are used outside'"; singleQuoteOutside = ' "Double quotes used inside so single quotes outside " '
20th Feb 2017, 7:59 AM
Chirag Bhansali
Chirag Bhansali - avatar
+ 2
And for a string containing both single and double quotes, many ways to achieve this: "The man said: \"What's for?\"" 'The man said: "What\'s for?" ... or even: """The man said: "What's for?"""" # EDIT: in fact this one cause an error with the fourth ending double quote :P '''The man said: "What's for?"'''
20th Feb 2017, 8:42 AM
visph - avatar
string = ' "Hello, world! " ' print(string)
20th Feb 2017, 7:12 AM
Leshark - avatar