ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

# math.isinf() method with example in Python

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

## Python math.isinf() method

math.isinf() method is a library method of math module, it is used to check whether a number is an infinity (positive or negative), it accepts a number and returns True if the given number is positive or negative infinity, else it returns False.

Syntax of math.isinf() method:

```    math.isinf(n)
```

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

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

Example:

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

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

Output:
False
True
```

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

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

# importing math module
import math

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

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

Output

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

ADVERTISEMENT

Comments and Discussions

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.