Python 3.5+mathterm
math.inf
constants
Positive infinity (a float). Used as the starting value when searching for a minimum, and in comparisons.
Syntax
math.inf
It is exactly the same value as float('inf'), just easier to read. Arithmetic with it never raises, but it quietly yields nan: math.inf - math.inf and math.inf / math.inf both produce nan rather than an error or zero. Note that dividing by a plain zero in Python does not give infinity — that is still ZeroDivisionError — and int(math.inf) fails with OverflowError.
Examples
import math
print(math.inf) # → inf
print(-math.inf) # → -inf
print(math.isinf(math.inf)) # → True
print(math.inf > 10**308) # → True
print(math.inf + 1) # → inf
print(math.inf - math.inf) # → nan
See also
Open in the full glossarydocs.python.orgReport an inaccuracy