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.The Zen of Python, by Tim Peters
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.
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!
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.
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 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 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')) 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 jokes 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.
Our Book Recommendations on Python (Affiliate)