Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.isfinite() Method

Python math.isfinite() Method

Python math Module Python math Module

Python math.isfinite() The method determines whether x is finite, returning True if x is neither infinity nor NaN, otherwise False.

Python version: 3.2

Syntax

The syntax of the math.isfinite() method is as follows:

math.isfinite(x)

Parameter Description:

Return Value

Returns a Boolean; True if x is neither infinity nor NaN, otherwise False.

Example

The following example checks whether numbers are finite:

Example

Import the math package

import

math

Check whether a number is finite

print

(

math

.

isfinite

(

2000

)

)

print

(

math

.

isfinite

(

45.34

)

)

print

(

math

.

isfinite

(

45.34

)

)

print

(

math

.

isfinite

(

math

.

inf

)

)

print

(

math

.

isfinite

(

float

(

"nan"

)

)

)

print

(

math

.

isfinite

(

float

(

"inf"

)

)

)

print

(

math

.

isfinite

(

float

(

"-inf"

)

)

)

print

(

math

.

isfinite

(

math

.

inf

)

)

print

(

math

.

isfinite

(

0.0

)

)

Output result:



True

True

True

False

False

False

False

False

True

Python math Module Python math Module