Did you know Python has several hidden easter eggs? Turns out, your favorite programming language isn’t just helpful for building applications, but also some quality humor. Let’s find some of the best ones.

5Hello World

If you’ve ever written code in any language, it’s highly likely your first program was to print “Hello World” on the console. You can do that in Python with a line of code.

However, there’s a more sophisticated way to do this. You can import a module called hello to print it.

Printing Hello, World in the console using the <strong>hello</strong> module in Python.

However, since Python 3.11, you need to call its main method to actually print the text.

Similar to the hello module, there’s also a phello module that does the same thing.

Printing Hello, World in the console using the <strong>phello</strong> module in Python.

The phello module even has a spam attribute you can call to print it twice. This works in versions that are older than 3.11.

In reality, these modules were added to Python to test if frozen modules worked as intended, as mentioned in theCpython source code.

Printing Hello, World in the console using by importing the spam attritbute from the <strong>phello</strong> module in Python.

So the next time you want to print ‘Hello, World!’, try this trick to have a chuckle or impress others.

4The Zen of Python

Every programming language has some rules and regulations, philosophies, and best practices. Python is no exception. Tim Peters, who was a major contributor to the Python programming language, wrote a set of principles for writing code in Python. This is commonly known as the “Zen of Python.” This literature piece was even incorporated into this language itself. To read it, all you have to do is run:

You’ll see the Zen of Python being printed on the screen.

The Zen of Python displayed in a Python shell.

If you look at the actual code of the file, you’ll find something interesting. The printed text is encrypted originally.

There’s another piece of code that is transforming the given text.

Trying to import braces from the __future__module giving a syntax error.

So, what’s happening is that the original text has beenencrypted using a substitution algorithmknown as ROT13. It’s a reversible algorithm. When you import thethismodule, that encrypted text is decrypted back to its original form and printed on the screen.

3Braces or No Braces

If you’ve even remotely used Python, you know that Python rarely uses curly braces, one of the most common syntax in many popular languages. Curly braces are usually used to define the scope of a code block, such as conditionals, loops, etc. Instead of braces, Python uses indentation. But will there ever be braces in Python? Not likely. Because the developers have already answered in the future module.

This is a special syntax error that you won’t find in any other case, implying that braces are never coming to Python. The future module in Python is used for implementing features in the current Python version that will be incorporated in a future version. This is done so that you can adapt to the new feature. It was a clever choice to fit this easter egg into this module.

Using diamond operators as inequality operators in Python.

2The FLUFL

The future module holds another interesting easter egg. If you’ve used logical operators in programming before, you know that in most languages, the symbol for inequality is != (exclamation mark followed by equal sign.) However, one of the core developers of Python, Barry Warsaw, also known as Uncle Barry, preferred to use diamond operators (<>) for inequality. Here’s the code bit.

FLUFL stands for Friendly Language Uncle For Life​​​​​​, which is apparently Uncle Barry’s title.

Generating a geohash using Python&rsquo;s geohash function in the antigravity module.

1antigravity

Another fun module to play with. I won’t spoil it for you but just run this code and experience it yourself.

This module also has a geohash() function. This function is used forgeohashingusing the Munroe algorithm.

Now, this may look totally out of place. However, this function is closely related to the previous easter egg you saw in the antigravity module. Pretty neat stuff.

It’s always interesting to find behind-the-scenes stuff about programming languages, especially if it puts a smile on your face. If this interested you, then you may considerlearning Pythonand do more fun stuff with it.