
The Zen of Python is a collection of 19
"guiding principles" for writing
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
s that influence the design of the
Python programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
.
Python code that aligns with these principles is often referred to as "Pythonic".
Software engineer
Software engineering is a branch of both computer science and engineering focused on designing, developing, testing, and maintaining software applications. It involves applying engineering principles and computer programming expertise to develop ...
Tim Peters wrote this set of principles and posted it on the Python
mailing list
A mailing list is a collection of names and addresses used by an individual or an organization to send material to multiple recipients.
Mailing lists are often rented or sold. If rented, the renter agrees to use the mailing list only at contra ...
in 1999.
Peters' list left open a 20th principle "for Guido to fill in", referring to
Guido van Rossum, the original author of the Python language. The vacancy for a 20th principle has not been filled.
Peters' Zen of Python was included as entry number 20 in the language's official
Python Enhancement Proposals and was released into the
public domain
The public domain (PD) consists of all the creative work to which no Exclusive exclusive intellectual property rights apply. Those rights may have expired, been forfeited, expressly Waiver, waived, or may be inapplicable. Because no one holds ...
.
It is also included as an
Easter egg
Easter eggs, also called Paschal eggs, are eggs that are decorated for the Christian holiday of Easter, which celebrates the resurrection of Jesus. As such, Easter eggs are commonly used during the season of Eastertide (Easter season). The ...
in the Python
interpreter, where it can be displayed by entering
import this.
In May 2020, Barry Warsaw (developer of
GNU Mailman) used it as the lyrics to a song.
Principles

The principles are listed as follows:
Being Pythonic
One of the principles, "There should be one-- and preferably only one --obvious way to do it", can be referenced as the "Pythonic" way.
The official definition of "Pythonic" is:
An idea or piece of code which closely follows the most common idioms of the Python language, rather than implementing code using concepts common to other languages. For example, a common idiom in Python is to loop over all elements of an iterable using a for
statement. Many other languages don’t have this type of construct, so people unfamiliar with Python sometimes use a numerical counter instead:
for i in range(len(food)):
print(food
As opposed to the cleaner, Pythonic method:
for piece in food:
print(piece)
Code that is difficult to understand or reads like a rough transcription from another programming language is called ''unpythonic''.
In practice
Since the release of the Zen of Python, there has been research done on its effectiveness and actual use among developers. Despite the difference in interpretation between beginners and experienced Python programmers, interviews among 13 Python programmers of varying skill show that the Zen of Python "positively influences the way developers write and talk about code".
Researchers extended this
case study
A case study is an in-depth, detailed examination of a particular case (or cases) within a real-world context. For example, case studies in medicine may focus on an individual patient or ailment; case studies in business might cover a particular f ...
to explore the use of Python
idioms on
GitHub
GitHub () is a Proprietary software, proprietary developer platform that allows developers to create, store, manage, and share their code. It uses Git to provide distributed version control and GitHub itself provides access control, bug trackin ...
repositories, and found that the usage of "Pythonic idioms" increased over time. Writing Python code that aligns with the Zen of Python may save
memory
Memory is the faculty of the mind by which data or information is encoded, stored, and retrieved when needed. It is the retention of information over time for the purpose of influencing future action. If past events could not be remembe ...
and
run time of Python programs. The desire to write in Pythonic code has led to
refactoring tools to help programmers achieve this goal.
See also
*
Convention over configuration
*
There's more than one way to do it
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language".
Perl was developed b ...
Notes
References
{{reflist
External links
PEP20 on Python websitePEP 20 ~ The Zen of Python by Tim Peters
2004 essays
Essays about computing
Programming principles
Python (programming language)