Python for Beginners 03: The Zen of Python

When learning a programing language, it makes sense to know about its background and its design principles. For Python, you should have a look at the Zen of Python. You can find them either on the Internet or it appears if you run import this (This kind of hidden joke is called “Easter egg”).

I am not going to give you a full explanation of each guideline, as there are many good ones on the Internet, but I am going to mention those who are most relevant for beginners or attention-grabbing.

From my understanding, many of the principles, in particular those 2-7, boil down to one key guideline: “keep it simple, but not at the expense of clarity”. The goal is to write code that can be understood, at a later point in time or by you. This is also the motivation behind comments. The combination of the principles 3. Simple is better than complex. and 4. Complex is better than complicated., shows that their creator was aware that not everything you develop will be easy and thus recommends not to sacrifice understandability for simplicity.

The principles 8. Special cases aren’t special enough to break the rules. and 9. Although practicality beats purity. are equally relevant for beginners and experts. Taken together, they recommend that you should stick to the “best practices” like simplicity and clarity, but again keep in mind that the purpose is improving your program, not following the rules.

The principles 13. There should be one– and preferably only one –obvious way to do it. and 14. Although that way may not be obvious at first unless you’re Dutch. are insider jokes. The first one points to the Perl programming language that prides itself of having many ways of solving the same problem, but this does also create confusion and additional work if you need to learn various possibilities. Python wants to avoid this, but of course there are exceptions. The allusion to being “Dutch” refers to the nationality of the creator of Python, Guido van Rosum.

In my opinion, knowing all of this gives you a good first idea of what the Zen of Python is about. Needless to say, if you are interested and as you are getting more and more involved with programming, I highly recommend to read them all and, of course, see what other people’s interpretations are.

Finally, you may think that it is kind of random to have 19 design principle and that having 20 would have been much more logical. There are some rumors that the writer of the principles, Tim Peters, wanted to leave the final one to the creator of Python, Guido van Rosum, whereas other sources say it is “some bizarre in-joke”. Whatever may be the truth, fact is that there is no 20th principle written down so far so there is a lot of speculation.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s