isinf(x) function checks whether x is positive or negative infinity. It's a method of math module. Python infinity is represented as float('inf').
isinf(x)
math
float('inf')
>>> import math >>> math.isinf(float('inf'))
True