isinf(n)
import math
print(math.isinf(2)) # False
print(math.isinf(-2)) # False
print(math.isinf(0.0)) # False
print(math.isinf(0/1)) # False
print(math.isinf(0.0/1)) # False
Note : 0.0 is considered finite.
import math
print(math.isinf(float('inf'))) # True
print(math.isinf(float('-inf'))) # True
print(math.isinf(float('nan'))) # False
Infinity in Calculations:print(math.isinf(1e308 * 2)) # Output: True
Infinity from Division:print(math.isinf(1 / 0.0)) # Output: True
Using with Lists:numbers = [10, float('inf'), float('-inf'), 42]
inf_values = [n for n in numbers if math.isinf(n)]
print(inf_values) # Output: [inf, -inf]
import math
print(math.isinf(float('inf'))) # True
print(math.isnan(float('nan'))) # True
import math
try:
result = 1.0 / 0.0
except ZeroDivisionError:
result = float('inf')
if math.isinf(result):
print("Result is infinity")
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.