Python Universal Infinity Value

1.5 · active · verified Fri Apr 17

The `infinity` library for Python provides a universal, all-in-one infinity value (`inf`) that can be compared to any other object, including numbers, lists, strings, and custom types, offering more flexible comparison behavior than `float('inf')`. It is currently at version 1.5 and has an infrequent release cadence for its stable feature set, reflecting its simple and focused utility.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing `inf` and its universal comparison capabilities with various data types, including numbers, strings, and collections, as well as accessing negative infinity.

from infinity import inf

# Universal comparison
print(f"inf > 1000: {inf > 1000}")
print(f"inf < 1000: {inf < 1000}")
print(f"inf == float('inf'): {inf == float('inf')}")

# Compare with non-numeric types (unique feature of infinity.inf)
print(f"inf > 'hello': {inf > 'hello'}")
print(f"inf > []: {inf > []}")
print(f"inf > {'a': 1}: {inf > {'a': 1}}")

# Using negative infinity
neg_inf = -inf
print(f"neg_inf < -1000: {neg_inf < -1000}")

view raw JSON →