The Easter eggs of Python

Some egg-citing yet little known things about python.

Rajdeep Singh
Jul 20, 2017 · 3 min read

1. The Zen of python

The Zen of Python was introduced in PEP20. It is a collection of 20 software principles that influences the design of Python. It is supposed to be 20 aphorisms but only 19 have been written so far.

>>> import thisThe Zen of Python, by Tim PetersBeautiful 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!

2. Comic fan, eh?

This is what python can do to you.

The antigravity module was just meant to be an easter egg referencing the xkcd comic mentioning Python.

>>> import antigravity

3. Hello World

Can a hello world program be any shorter than this?

Python 2 version:

>>> import __hello__
Hello world...

On Python 3, you get a slightly more enthusiastic message. After all, Python 3 is meant to be the future of Python.

>>> import __hello__
Hello world!

__hello__ is a frozen module intended as a test case for frozen module support. It’s source code is automatically generated by the Python freeze utility. More about that here.

4. So you’re a C programmer ?

Prefer C style braces instead of indentation ?

Python is designed to be elegant and mandatory indentation is an essential part of this. The library braces from __future__ module was supposed to change this, allowing to use C-style braces. This was of course a joke and attempting to import braces produces a rather aggressive “not a chance” error.

>>> from __future__ import braces
File "<stdin>", line 1
SyntaxError: not a chance

5. The name ‘Python’

The name has nothing to do with reptiles, instead it comes from the BBC show ‘Monty Python’s Flying Circus’. The official Python guide suggests:

Making references to Monty Python skits in documentation is not only allowed, it is encouraged!

6. Uncle Barry

Barry Warsaw, or as he is also known, Uncle Barry was chosen as Guido’s successor after he decided to step aside as the BDFL of Python. His official title is Friendly Language Uncle For Life(FLUFL).

So the statement from __future__ import barry_as_FLUFL replaces != operator with <> in Python 3.

>>> from __future__ import barry_as_FLUFL
>>> 1 <> 2
True

7. Rules are meant to be broken

So the code that generates the Zen of Python breaks some of its own aphorisms by being ugly and not beautiful. Have a look here.

The algorithm being used to generate the Zen is rot13 encoding.

)
Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade