Skip to content
Related Articles

Related Articles

Improve Article

Top 5 Easter Eggs in Python

  • Last Updated : 22 Jul, 2021
Geek Week

Python is really an interesting language with very good documentation. In this article, we will go through some fun stuff that isn’t documented and so considered as Easter eggs of Python.

1. Hello World 

Most of the programmers should have started your programming journey from printing “Hello World!”. Would you believe that Python has a secret module to print “Hello World” and the name of the module is __hello__

Python3




import __hello__ 

Output:

Hello world!

2. Antigravity

If you feel bored typing code all day, then check the antigravity module in Python which redirects you to

https://xkcd.com/353/ a web-comic.



Python3




# redirects you to https://xkcd.com/353/
import antigravity

3. Zen of Python

“Zen of python”  is a guide to Python design principles.  It consists of 19 design principles and it is written by an American software developer Tim Peters. This is also by far the only ‘official’ Easter egg that is stated as an ‘Easter egg’ in Python Developer’s Guide. You can see them by importing the module “this”.

Python3




import this

Output:

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!

4. The FLUFL [Friendly Language Uncle For Life]

Recognized that the != inequality operator in Python 3.0 was a horrible, finger pain-inducing mistake, the FLUFL reinstates the <> diamond operator as the sole spelling.

Python3




from __future__ import barry_as_FLUFL
  
1 <> 2
1 != 2

Output:

True
SyntaxError: with Barry as BDFL, use '<>' instead of '!='

5. Braces

Unlike most of the language, Python uses indentation instead of curly braces “{ }”. While making a transition from languages like C++ or JAVA to Python it is a bit difficult to adapt to indentation. Thus if we try to use braces using __future__ module, Python gives a funny reply “not a chance”.

Python3




from __future__ import braces

 Output:

File "<stdin>", line 1
SyntaxError: not a chance

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :