0
What is difference between writing strings in single or double quotes,or when to use single and double quotes
3 Answers
+ 2
this works in c++ ..but in python i don't think it's true
@P Sandesh Baliga
+ 2
There's no actual difference other than what Aleksander said - to avoid unnecessary escaping, for example:
print ("That's")
You can concatenate strings written with different types of quotes, like: "abc" + 'def' and it will still work.
The only thing to follow is to use them in pairs - you can't begin a string with an apostrophe and end it with quote or vice versa. They have to match.
0
In python both works for string but as a convention we use double quotes for real string e.g. to be displayed somewhere, and single quotes for all the internally used strings e.g. is when we call a key of field in dictionary, regular expressions etc.
Another explanation is that we use single quotes when we need to put double quotes inside of a string without escaping and vice versa