isinf()

isinf(number) returns Boolean , True if the input number is positive infinite or negative infinity, False otherwise.
isinf(n)  

Example
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:
Overflowing a large number results in infinity.
print(math.isinf(1e308 * 2))  # Output: True
Infinity from Division:
Division by zero results in positive infinity.
print(math.isinf(1 / 0.0))  # Output: True
Using with Lists:
This filters out infinity values from a list.
numbers = [10, float('inf'), float('-inf'), 42]
inf_values = [n for n in numbers if math.isinf(n)]
print(inf_values)  # Output: [inf, -inf]

Difference Between isinf() and isnan()

import math
print(math.isinf(float('inf')))  # True
print(math.isnan(float('nan')))  # True

Use Case: Handling Division by Zero

import math

try:
    result = 1.0 / 0.0
except ZeroDivisionError:
    result = float('inf')

if math.isinf(result):
    print("Result is infinity")

isfinite()
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate 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.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer