Double or single quotes? | Sololearn: Learn to code for FREE!

+2

Double or single quotes?

What difference between double or single quotes?When to use them?

3/22/2018 7:49:40 PM

HBhZ_C

6 Answers

New Answer

+13

You can use both. But if you start a string with one type, then you must end it with the same type. The possibility to use both types of quotes is, that you can use the other type within the string, without having them to escape by a backslash. Example: a = "asdf\"ghjk" print(a) b = 'asdf"ghjk' print(b)

+8

You can use both, just don't mix them: "word' and 'word" are errors. Also, like @Jan stated, if you need to include quotes in your string, use a backslash (\)

+7

simple example: does work : print("he is 'smart' ...") doesn't work : print('he is 'smart' ...') try it

+4

The reason the ‘smart’ doesn’t work is because you need the \ sign before each single quote.

+3

I don’t believe there is a difference, but I use double, because almost every other language requires double.

0

Double quotes are better /s it doesn't really matter provided that strings start and end with the same one, but it's more convenient personally for me to use double because I rarely have to include speech in string and therefore use the ' character more often within strings and not having to put a \ (which is halfway across the keyboard) makes things quicker(and nicer looking)