Wednesday, November 10, 2010

The Zen of Python

In this post I am going to introduce you to what began as a kind of joke by long time Pythoneer Tim Peters but later sustained through more than 20 years to become a outline of the philosophy of the Python programming language. Developers at the Python Software Foundation as well as programmers using Python have found guidance in the Zen of Python.

You can find the Zen of Python in a module called 'this' in your very own Python installation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 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!
link - raw This paste is brought you by Friendpaste.


As you can see, the Zen of Python is written in a rather poetic and humorous way. Looks like Python programmers do have a lot of sense of humor. For one more Python joke type in:

1
from __future__ import braces
link - raw This paste is brought you by Friendpaste.


in your command prompt.