Today I learned about a Python Easter Egg hidden in the hash of two special float values.
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.
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.