The Zen of Python
You can access the Zen of Python with the following import
:
>>> import this
The Zen of Python, by Tim Peters
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!
00:00
In this first lesson, I want to introduce you to The Zen of Python by Tim Peters. If you enter any more modern Python interpreter and then type import this
and press Enter, then you get as a printout to your console a poem called The Zen of Python that was written by Tim Peters. The sentences in this poem encode a bit the idea of what does it mean to write Pythonic code.
00:25 You might see some of these sentences around as well. So, for example, “Simple is better than complex,” is quoted quite often, or “There should be only one obvious way to do something,” or “Readability counts.” You might encounter some of these sentences when a person argues for writing Pythonic code, and this is where they come from.
00:44 They all originate from The Zen of Python by Tim Peters. This poem is a bit of a guideline on how to write Pythonic code, but at the same time, it’s also a bit of a joke because the whole module was written in a way that is very un-Pythonic, so it just encodes a bit also this feeling of the Python community—that yes, you want to write very readable code, but also that you want to have fun while doing it.
01:07
This is also why this poem is quite loved by the Python community and often quoted. So now you know how to get to it. You just type import this
, and then it prints out The Zen of Python.
01:18 I encourage you to try this in your interpreter and read over the poem, think about some of the sentences in there, and think about how they relate to the later lessons in this course, where you’re going to learn about some Pythonic ways of writing code. That’s all about The Zen of Python. In the next lesson, you’ll learn about how to set up your scripts and also how to handle statements in Python.
Become a Member to join the conversation.