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.

Improve your Python ๐Ÿ fluency and algorithm knowledge ๐ŸŽฏ

Get ready for 12 intense days of problem-solving. The โ€œAlgorithm Mastery Bootcampโ€ starts December 1st and it will feature 24 programming challenges, live analysis sessions, a supportive community of like-minded problem-solvers, and more! Join now and become the Python expert others can rely on.

Previous Post Next Post

Blog Comments powered by Disqus.