Today I learned about a Python Easter Egg hidden in the hash of two special float values.

Hash of infinity

Today I learned that the values float("inf") and float("-inf") have two very special hashes:

>>> hash(float("inf"))
314159
>>> hash(float("-inf"))
-314159

In case you can't tell, those are the first few digits of the mathematical constant \(\pi\):

>>> import math
>>> math.pi
3.141592653589793
# ^^^^^

I learned about this during the CPython panel held at EuroPython 2025, after the hosts ลukasz & Pablo asked the panel if they know what the hash of -1 was.

Become a better Python ๐Ÿ developer, drop by drop ๐Ÿ’ง

Get a daily drop of Python knowledge. A short, effective tip to start writing better Python code: more idiomatic, more effective, more efficient, with fewer bugs. Subscribe here.

Previous Post Next Post

Blog Comments powered by Disqus.