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 the smartest Python ๐Ÿ developer in the room ๐Ÿš€

Every Monday, you'll get a Python deep dive that unpacks a topic with analogies, diagrams, and code examples so you can write clearer, faster, and more idiomatic code.

Previous Post Next Post

Blog Comments powered by Disqus.