0

What is difference between writing strings in single or double quotes,or when to use single and double quotes

8th Dec 2016, 6:16 AM
Ashish Ranjan
Ashish Ranjan - avatar
3 Respostas
+ 2
this works in c++ ..but in python i don't think it's true @P Sandesh Baliga
8th Dec 2016, 6:40 AM
Ashish Ranjan
Ashish Ranjan - avatar
+ 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.
10th Dec 2016, 12:08 AM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
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
8th Dec 2016, 7:38 AM
Aleksander Zakrzewski
Aleksander Zakrzewski - avatar