Desk2Mob

Desk2Mob

Desk2Mob

Single quotes and double quotes in Python

Single quotes and double quotes in Python

In Python, single quotes and double quotes create the same kind of string. These two lines are equivalent:

foo = "bar"
foo = 'bar'

If Jupyter or the Python console shows the value as 'bar', that does not mean Python changed your double quotes into single quotes. The console is showing the string representation, also called repr. Python often chooses single quotes when displaying that representation.

foo = "bar"

foo
# 'bar'

print(foo)
# bar

So which one should you use?

  • Use either single quotes or double quotes for normal strings.
  • Be consistent inside the same project or file.
  • Use double quotes when the string contains a single quote.
  • Use single quotes when the string contains double quotes.
  • Use triple double quotes for docstrings.

Good examples

message = "It's working"

html = '<p class="title">Hello</p>'

def hello():
    """Return a greeting message."""
    return "Hello"

There is no technical difference between "bar" and 'bar'. The preferred style is usually consistency. Many Python teams choose one style and use the other only when it avoids escaping.

good = "It's easy to read"
less_good = 'It\'s harder to read'

Final answer

You do not need to prefer single quotes or double quotes because of Python itself. Both are correct. Use whichever style your project follows, and switch when it makes the string easier to read.

Posted on June 08, 2026 by Amit Pandya in python


All Posts