Is there any reason to use double or single quotes?



If both are valid, why would you use double or single quotes for any given string?


It depends on the string you’re writing or storing for sure. The important thing is to always have the same type of quote on the outside, and always have a closing outside quote for an opening outside quote.
If we need to write a string with an apostrophe in the middle, it’s best to use double quotes on the outside, otherwise it’ll think we have an extra quote!

print “This looks right, doesn’t it?”

print ‘This doesn’t look right, does it?’

See how the second example looks like we closed off our string after the ‘n’ in “doesn’t”?
Another common practice is using double quotes for strings and single quotes for single characters, like ‘n’.

FAQ: Learn Python - Python Syntax - Strings

I still don’t understand why you would use double quotes. It seems pointless to me to have a double quote.


Why does it seem pointless?

if i had to choice between:

'This doesn\'t look right, does it?'


"This doesn't look right, does it?"

i would pick the latter, so i don’t have to escape the ' used in the string.