I have been always mixing these two notations, regarding them both as a string in Python.
What are the differences between them?
Under what circumstances can we only use one of them?
I have been always mixing these two notations, regarding them both as a string in Python.
What are the differences between them?
Under what circumstances can we only use one of them?
They're the same. The only time it ever matters is that you have to escape the delimiter character: "\""
vs '"'
.
Personally, I usually use '
for strings that aren't "user-visible" and "
for strings that are, but I'm not completely consistent with that and I don't think it's common practice.
No difference at all: they mean exactly the same thing. Yes, that's unusual for Python ;-)
Some programmers like to put one-character strings in single quotes, and longer strings in double quotes. Probably a habit carried over from C. Do what you like :-)
Ah: a lot more discussion here.
They are equal and depend on your preferences
but you can do this:
>>> print 'Double" quote inside single'
Double" quote inside single
>>> print "Single' quote inside double"
Single' quote inside double
They are the same, though I prefer to use 'single quotes'
as they're easier to read