Computer >> Computer tutorials >  >> Programming >> Python

How can I represent an infinite number in Python?


A number equivalent to infinity can be assigned to a float variable by putting 'inf' as argument to float() function

>>> a=float('inf')
>>> a
inf

It is also possible to achieve same effect by assigning inf constant in math module

>>> import math
>>> a=math.inf
>>> a
inf