ADVERTISEMENT
ADVERTISEMENT

# math.isfinite() method with example in Python

Python math.isfinite() method: Here, we are going to learn about the math.isfinite() method with example in Python.
Submitted by IncludeHelp, on April 18, 2019

## Python math.isfinite() method

math.isfinite() method is a library method of math module, it is used to check whether a given number is a finite number of not, it accepts a number (integer/float, finite, infinite or NaN), and returns True if number neither an infinity nor a NaN (Not A Number), else it returns False.

Syntax of math.isfinite() method:

```    math.isfinite(n)
```

Parameter(s): n – a number that has to be checked whether it is finite or not.

Return value: bool – it returns a Boolean ("True" or "False") value.

Example:

```    Input:
a = 10
b = float('inf')

# function call
print(math.isfinite(a))
print(math.isfinite(b))

Output:
True
False
```

### Python code to demonstrate example of math.isfinite() method

```# python code to demonstrate example of
# math.isfinite() method

# importing math module
import math

# math.isfinite() method test on finite value
print(math.isfinite(10))
print(math.isfinite(0))
print(math.isfinite(10.23))
print(math.isfinite(0.0))

# math.isfinite() method test on infinite value
print(math.isfinite(float('inf')))
print(math.isfinite(float('-inf')))
print(math.isfinite(float('nan')))
```

Output

```True
True
True
True
False
False
False
```
ADVERTISEMENT

Preparation

ADVERTISEMENT

Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.