in Programming, Python, Tutorial

The Top 5 Easter Eggs in Python

Despite being a very serious language, Python is full of Easter eggs and hidden references. This post shows the top 5:

  1. Hello World…
  2. The Zen of Python
  3. Antigravity
  4. C-Style braces instead of indentation
  5. Monthy Python references

I have covered the 5 most interesting features of Python in this post.

1. Hello World…

As a programmer, you should be familiar with Hello World. Python has a library that does that that.

>>> import __hello__
Hello World...

On Python 3 you get a slightly more enthusiastic message: Hello world!. Reimporting the library doesn’t make the message reappear.

2. The Zen of Python

Another hidden library in Python is this, which prints a poem by Tim Peters called The Zen of Python:

>>> import this
The Zen of Python, by Tim Peters

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!

3. Antigravity

The most infamous easter egg in Python is the antigravity one, which redirects to an xkcd strip:

import antigravity

python

4. C-Style braces instead of indentation

Python is designed to be elegant; mandatory indentation is an essential part of this. The library braces were supposed to change this, allowing to use C-Style braces instead of indentation. This is of course a joke, since attempting to import it produces a rather passive-aggressive “not a chance“.

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

5. Monthy Python references

The name Python has nothing to do with reptiles. Rather the opposite, it comes from the BBC show “Monty Python’s Flying Circus”. As the official Python guide suggests:

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

This has led developers to include several hidden references not only in the official documentation, but also in their code. For instance in Python, metasyntactic variables takes the names of spam and egg, rather than the more traditionally used foo and bar. This is a clear reference to the Monty Python sketch Spam. You can see this, for example, in the official documentation (Input and otuput) in which there are many other references such as:

>>> print 'We are the {} who say "{}!"'.format('knights', 'Ni')
We are the knights who say "Ni!"

From Coursera to Codeacademy, basically every serious Python tutorial make references to Monty Python.

💖 Support this blog

This websites exists thanks to the contribution of patrons on Patreon. If you think these posts have either helped or inspired you, please consider supporting this blog.

Twitter_logo

YouTube_logo
📧 Stay updated

You will be notified when a new tutorial is relesed!

📝 Licensing

You are free to use, adapt and build upon this tutorial for your own projects (even commercially) as long as you credit me.

You are not allowed to redistribute the content of this tutorial on other platforms. Especially the parts that are only available on Patreon.

If the knowledge you have gained had a significant impact on your project, a mention in the credit would be very appreciated. ❤️🧔🏻

Write a Comment

Comment

  1. and try this:

    import this

    print()
    for c in this.s:
    if c in this.d:
    print(this.d[c],end=”)
    else:
    print(c,end=”)
    print()

Webmentions

  • Tutorial Series - Alan Zucconi December 23, 2019

    […] The Top 5 Easter Eggs in Python […]