Single or double quotes in Python?

By on 20 September 2022

Whatever you think about Twitter these days, it’s pretty handy for us developers to ask questions and get inputs 💡

Last week I asked about single vs double quotes in Python:

I thought double quotes were a given, black – “The Uncompromising Code Formatter”, defaults to them and I personally find them pleasant to the eye.

Until I read about a different formatter in Fluent Python (2nd ed) called blue (“a somewhat less uncompromising code formatter than black”) and its preference for single quotes:

Given the goal of enforcing a “standard” coding style, blue is better than black because it follows Python’s own style of using single quotes by default, double quotes as an alternative … [truncated code example] … The preference for single quotes is embedded in repr(), among other places in CPython. The doctest module depends on repr() using single quotes by default. One of the authors of blue is Barry Warsaw, coauthor of PEP 8, Python core developer since 1994, and a member of Python’s Steering Council from 2019 to present (July 2021). We are in very good company when we choose single quotes by default. If you must use black, use the black -S option. Then it will leave your quotes as they are.

Fluent Python (2nd edition) by Luciano Ramalho

So now I’m torn, should I change to single quotes?

Here is a summary of some of the interesting replies to my question on Twitter:

– Single. But it depends from the context. + I don’t have a preference, either one is fine, as long as it’s consistent along the whole file! 

This is great point. As much as you want to enforce PEP8, standards and thus the use of single vs double quotes, if you are tied to an existing code base, you want to prefer consistency above anything else.

– Single, but not enough that I feel compelled to tweak/replace black 🙂 

Yep using black is a strong argument for using double quotes. But thanks to Fluent Python I learned about the -S to leave quotes alone (or switch to blue, I yet have to try it …)

– Single quotes are always my first choice since they require just one keystroke. 

This is indeed an advantage I’m experimenting with: how much does it speed up the actual act of writing code? And thanks to auto-formatting you can still write single quotes, yet have them swapped out for double quotes in your final code 😮

– Double. Allows using apostrophes in strings and makes the string statement look more explicit and final. And the code looks more readable and pro overall. Single-quotes scattered everywhere makes the code look messy like it has been quick-scripted together. It smells. + If it’s an f-string with quotes inside the curly braces, those are double quotes instead of escaped single quotes. 

The embedding of single quotes (and not having to escape them like \' which is quite ugly) has been one of my main reasons for me to stick with double quotes so far (apart from habits being hard to break 😅)

– Single quotes. The same as Python prefers (in reprs). 

Following Python’s conventions is always a great argument and one thing that stood out from the Fluent Python quote above.


I found it interesting to at least reflect a bit on this. Fortunately, thanks to having auto-formatters, you can mostly ignore this (“set and forget“). For example by using your favorite auto-formatter with a tool like pre-commit (you can see me set it up here). So you can use whatever you like when writing code, to have it be consistently auto-formatted when committing your code.

As long as we’re consistent! I think that’s the main takeaway from this article.

Feel free to use mentioned tweet to add your 2 cents …

Thanks for reading.

Want a career as a Python Developer but not sure where to start?