python logo

Python Commandments

The Zen of Python

There’s a poem in Python - The Zen of Python, called.

The Zen of Python, The Path of Python,

It summarizes the style of Python and can be used to guide programming in Pythonista.

One of the basic criteria for Python is to write code that is “Python Zen” - concise, clear, elegant

The Zen of Python, by Tim Peters

The poem is:

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

Typing import this into the Python shell will show Tim Peters’ The Zen of Python.

>>> import this
the zen of python

This is actually an easter egg. It was introduced in 2004.

If you open the file /usr/lib64/python3.7/this.py, you can see the joke doesn’t stop there.

this module source, zen of python So it had been sneakily added into the Python standard library.