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 do the following:
>>> 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 of them 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 guidelines are 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.
Besides just googling it, you can see the Zen of Python if you run the following Python command, try it out!
>>> import this
Indeed, there is another awesome aspect of this easter egg. If you are interested, take a look in the source code of the module this.
In the evolving process of Python, the debate of the inequality operator had two opposite sides. The != version finally won the battle against <>, which you can obviously see in the documentation or by trying it out.
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 use the other variant!
>>> from __future__ import barry_as_FLUFL >>> 0 != 1 SyntaxError: with Barry as BDFL, use '<>' instead of '!=' >>> 0 <> 1 True >>> 1 <> 1 False
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).
You can try to import the braces from the __future__ build-in module, 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 happens:
>>> import antigravity
Is it possible to create a hash of infinity or a NaN value? In Python it is!
>>> hash(float('inf')) 314159 >>> hash(float('nan')) 0
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 hidden in the whole Python environment, here are a few examples:
- Funny quote of Monty Python and the Holy Grail in the official input and output documentation
- Instead of using foo and bar, many tutorials use spam and egg
- The name of the wheel ZIP-format for Python’s sdist packages is based on the Cheese Shop sketch by Monty Python
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!
There is nothing that excites me more than solving problems and understanding complex concepts. I want to share this enthusiasm by making complex things as simple as possible, so everyone can understand them. Nothing is more frustrating than trying to understand a topic with incomprehensible explanations. That’s why I want to inspire you to become a better developer by simplifying concepts and explaining issues clearly.