7 Python Easter Eggs

Python is an exciting language and has always some surprises in store, no matter how long you have been working with it. In this Post, I will present 7 really cool easter eggs in Python. Feel free to try them out on your own, I hope you enjoy it!

Hello World#

I guess nearly everyone who ever got in touch with Python wrote the famous 'Hello World' program in Python, or at least know how to code it. But there is another easy way besides printing it, you can also use the built-in implementation:

>>> import __hello__
Hello world!

The Zen of Python#

This easter egg is probably the most known one, at least the experienced Python programmers are likely to know it. Tim Peters created 20 guiding principles, 19 ones are written down as the Zen of Python. This feature is also documented in the PEP 20 guideline.

The Zen of Python is telling Python's philosophy and best practices. The message is mainly about code quality, design, and how to solve problems. If you follow them, you will improve your code and the way you solve problems.

You can see the Zen of Python by importing the module this, try it out!

>>> import this

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!

The Zen of Python, by Tim Peters

Indeed, there is another awesome aspect of this easter egg. If you are interested, take a look at the source code file of the module this.

Uncle Barry#

In the evolving process of Python, the debate of the inequality operator implementation had two opposite sides some time ago. The != version finally won the battle against the diamond operator >< to avoid any ambiguity and improve the readability.

The well-known Python programmer Barry Warsaw (aka Uncle Barry) had the honor to become the Friendly Language Uncle For Life (FLUFL). Sadly, he is on the losing side of the debate and prefers the version for the inequality operator. But if you have the same vision as Uncle Barry, you can simply import a library to change the rules and use the other variant!

>>> from __future__ import barry_as_FLUFL
>>> 0 != 1
SyntaxError: with Barry as BDFL, use '<>' instead of '!='
>>> 0 <> 1
>>> 1 <> 1

Using the official inequality operator then raises a SyntaxError, you have to use the other operator instead. As an April fool, PEP 401 says that this operator got enacted by the FLUFL in 2009 (and some other stupid changes).


One of the most amazing differences between coding in Python and most of the other programming languages (Java, C++, JavaScript, etc.) is the following: No curly braces! (except for dicts and sets, but they don't count). I think everyone who had to deal with a code containing thousands of curly braces will appreciate the simplicity of Python with nothing more than indentations. It's just easier and more readable without curly braces, so Python wants to show that they aren't tolerated in the language.

You can try to import the braces from the __future__ build-in module if you can't resist the temptation to use them, but look what happens:

>>> from __future__ import braces
SyntaxError: not a chance


You can experience antigravity by Python coding, believe me! Just run the following code and see what appears on your screen:

>>> import antigravity


Is it possible to create a hash of infinity or a NaN value? In Python it is!

>>> hash(float('inf'))
>>> hash(float('nan'))

Monty Python References#

The Name Python is an homage to the English comedy group Monty Python. Furthermore, the docs say that the language is named after the BBC show “Monty Python's Flying Circus”.

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

Official Python Tutorial

There are some references to Monty Python jokes hidden in the whole Python environment, here are a few examples:

These are a few Monty Python reference easter eggs, I am sure you can find more by exploring the Python documentation and tutorials!

I presented some cool and funny easter eggs you can find by using Python, I hope you enjoyed it! If you want to explore more funny and interesting Aspects of Python, you can take a look at the Python Humor page in the documentation. If you have any feedback or another cool easter egg that is still missing here, let me know in the comments below!