The quest for the "definitive Python style guide"

Hey there,

Code style guidelines are an endless source of discussions and arguments among developers.

A while ago, newsletter member Andrew reached out to me with this question:

~~~

Hi Dan,

I've been enjoying your email updates and python tips! Thank you for doing this! I have a quick question. For someone new to Python, I'm trying to find the definitive style guide. A quick Google search turns up things like this:

https://www.python.org/dev/peps/pep-0008/
https://www.python.org/dev/peps/pep-0257/
https://google.github.io/styleguide/pyguide.html

Although it appears the first link has been updated, the first two seem rather old (2001)? Are these still the main go-to style guides? The next one looks to have been created by Google...but why would they do this if a definitive guide already exists?

As a contrast, the PHP-FIG page provides an excellent, and well laid-out recommended style guide: http://www.php-fig.org/psr/psr-1/

I guess I'm looking for the equivalent to that. I much appreciate any help you can offer. And again thank you for your emails and video tutorials!

~~~

One of the things I like the most about Python is it's high readability.

I strongly believe that "code is communication"—

And just like there are generally accepted stylistic rules & guidelines for written communication in English, there are code style guides for writing Python.

Sticking to these guidelines is one honking great idea.

They make it easier for development teams to work together. And even if you're working on a project by yourself, they'll help you make changes in the future.

My thinking there is this:

When you're reading code, your brain works like a Python compiler.

It first needs to parse the program text and then turn it into some internal representation before you can understand and modify the code.

If your code uses inconsistent styling and formatting rules, it trips up your brain's pattern recognizer and slows it down.

Therefore it takes longer to read and modify "sloppy" code.

And these "micro delays" add up and cost you productivity. They also make you feel exhausted quicker.

(I can't cite scientific proof for this theory, but from experience it's what I think happens. I talk about this a lot in my code review videos on YouTube.)

Alright, back to the original question, which sort of went like this:

"Okay great, but WHICH style guide should I use?"

Actually, the style guides Andrew mentioned are the most commonly used ones in Python.

Some people don't like Google's Python style guide because it has some "Google-isms" in it (how import statements are laid out etc.)

I'd say Google's guide is worth a read for a second opinion, but:

Generally the PEP 8 style guide is the preferred choice in the community and I also recommend and use it personally.

It's a great idea to mix PEP 8 with PEP 257 for docstring conventions. Those two make a great combo.

And yes, PEP 8 and PEP 257 are rather "well-seasoned"—which is NOT a bad thing.

These style guides have been maintained and fine-tuned for over a decade. Both are valuable resources that any Python developer worth their salt should know.

If you're ready to jump in but you're looking for an easier to read web-version of PEP 8 with improved formatting, check out pep8.org.

Happy Pythoning!

— Dan Bader

Older messages

New Python tutorials on Real Python

Saturday, June 20, 2020

Hey there, There's always something going on over at realpython.com as far as Python tutorials go. Here's what you may have missed this past week: Python Keywords: An Introduction Python

How to prepare for a Python coding interview

Sunday, June 14, 2020

Hey there, Participating in a "Silicon Valley style" coding interview can feel scary as heck. Unlike other professionals, it seems to be okay for software developers to expect to get

New Python tutorials on Real Python

Saturday, June 13, 2020

Hey there, There's always something going on over at realpython.com as far as Python tutorials go. Here's what you may have missed this past week: Python Community Interview With Kattni Rembor

New Python tutorials on Real Python

Saturday, June 6, 2020

Hey there, There's always something going on over at realpython.com as far as Python tutorials go. Here's what you may have missed this past week: Build Physical Projects With Python on the

I'm certified

Friday, June 5, 2020

Hey there, One of the "shameful secrets" of my career is that I'm a certified "Scrum Product Owner." Let me tell you how this came to be: One fine Tuesday morning my manager

You Might Also Like

Import AI 399: 1,000 samples to make a reasoning model; DeepSeek proliferation; Apple's self-driving car simulator

Friday, February 14, 2025

What came before the golem? ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

Defining Your Paranoia Level: Navigating Change Without the Overkill

Friday, February 14, 2025

We've all been there: trying to learn something new, only to find our old habits holding us back. We discussed today how our gut feelings about solving problems can sometimes be our own worst enemy

5 ways AI can help with taxes 🪄

Friday, February 14, 2025

Remotely control an iPhone; 💸 50+ early Presidents' Day deals -- ZDNET ZDNET Tech Today - US February 10, 2025 5 ways AI can help you with your taxes (and what not to use it for) 5 ways AI can help

Recurring Automations + Secret Updates

Friday, February 14, 2025

Smarter automations, better templates, and hidden updates to explore 👀 ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏ ͏

The First Provable AI-Proof Game: Introducing Butterfly Wings 4

Friday, February 14, 2025

Top Tech Content sent at Noon! Boost Your Article on HackerNoon for $159.99! Read this email in your browser How are you, @newsletterest1? undefined The Market Today #01 Instagram (Meta) 714.52 -0.32%

GCP Newsletter #437

Friday, February 14, 2025

Welcome to issue #437 February 10th, 2025 News BigQuery Cloud Marketplace Official Blog Partners BigQuery datasets now available on Google Cloud Marketplace - Google Cloud Marketplace now offers

Charted | The 1%'s Share of U.S. Wealth Over Time (1989-2024) 💰

Friday, February 14, 2025

Discover how the share of US wealth held by the top 1% has evolved from 1989 to 2024 in this infographic. View Online | Subscribe | Download Our App Download our app to see thousands of new charts from

The Great Social Media Diaspora & Tapestry is here

Friday, February 14, 2025

Apple introduces new app called 'Apple Invites', The Iconfactory launches Tapestry, beyond the traditional portfolio, and more in this week's issue of Creativerly. Creativerly The Great

Daily Coding Problem: Problem #1689 [Medium]

Friday, February 14, 2025

Daily Coding Problem Good morning! Here's your coding interview problem for today. This problem was asked by Google. Given a linked list, sort it in O(n log n) time and constant space. For example,

📧 Stop Conflating CQRS and MediatR

Friday, February 14, 2025

​ Stop Conflating CQRS and MediatR Read on: m​y website / Read time: 4 minutes The .NET Weekly is brought to you by: Step right up to the Generative AI Use Cases Repository! See how MongoDB powers your