Search⌘ K
AI Features

Inpinity

Learn how Python computes the hash of infinity in float values and how it differs between Python versions. This lesson helps you understand a subtle aspect of Python's numeric handling to write more precise and error-free code when dealing with infinite values.

We'll cover the following...

The spelling is intended. Inpunity is also acceptable.

⚠️ The following code is meant for Python 3.x versions.

Python 3.5
infinity = float('infinity')
print("Hash of inf: ", hash(infinity))
print("Hash of -inf: ", hash(float('-inf')))

Explanation

  • Hash of infinity is 105×π-10^5 \times \pi
...