
this.These guiding principles were first presented by Tim Peters, one of Python’s founding contributors, in 1999. The Zen of Python is a set of golden principles or axioms for the best programming practices in Pythonic style. Namespaces are one honking great idea - let's do more of those! May 5 - This article was written by Aamir Shahzad Hashmi, a member of Educative’s technical content team.

Youll find out how they originated and whether you should follow them. If the implementation is easy to explain, it may be a good idea. In this tutorial, youll be exploring the Zen of Python, a collection of nineteen guiding principles for writing idiomatic Python. If the implementation is hard to explain, it's a bad idea.

There should be one- and preferably only one -obvious way to do it.Īlthough that way may not be obvious at first unless you're Dutch.Īlthough never is often better than *right* now. Some of the principles that influenced the design of Python are included as an Easter egg and can be read by using the command inside Python interpreter interactive mode: > import this The Zen of Python, by Tim Peters Beautiful is better than ugly. In the face of ambiguity, refuse the temptation to guess. You'll find out how they originated and whether you should follow them. Every time I execute my python code, the following appears in the terminal window: The Zen of Python, by Tim Peters. The statements in the zen of Python are as follows. What's the Zen of Python In this tutorial, you'll be exploring the Zen of Python, a collection of nineteen guiding principles for writing idiomatic Python. Lets take a look at one of the idioms listed in these guiding principles. One little Easter Egg in Python is the ability to print the Zen of Python using the command import this. Special cases aren't special enough to break the rules. The Zen of Python is a collection of 20 guidelines or heuristics suggested by Tim Peters. The Zen of Python is one of these PEPs and is documented as PEP20.
#Print zen of python code
(Another different sort of PEP is PEP20.There is a well known Easter Egg in Python called import this that when added to your code will automatically output The Zen of Python, by Tim Peters

The Zen of Python Beautiful is better than ugly. Sticking to the convention makes it easier for others to read your code (and trains your own eyes to better read others' code).įor example, make your varaible and function names descriptive (there is never a good reason to call a variable temp), and use lowercase_with_underscores. 1 Post-History: 2 Table of Contents Abstract Long time Pythoneer Tim Peters succinctly channels the BDFL’s guiding principles for Python’s design into 20 aphorisms, only 19 of which have been written down. The indented print statement lets Python know that it should only be executed if the if statement returns True.

#Print zen of python how to
If you browse the PEPs you can read about the rationale for many language features at the time they were first proposed, and see some potential new features ( PEP465 is exciting for scientists!).Īnyways, PEP8 is a little different, it contains all the style recommendations for coding in Python, such as where to put whitespace and how to name things. PEP stands for Python Enhancement Proposals and it is where ideas for changing Python are formalized, to eventually become part of the langauge or die out. (in a python shell, type 'import this') Raw import this The Zen of Python, by Tim Peters Beautiful is better than ugly.
