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

Python math.isnan() Method

Python math.isnan() Method

Python math Module Python math Module

Python math.isnan() The method determines whether a number is NaN (not a number), returning True if the number is NaN, otherwise False.

Python version: 3.5

Syntax

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

math.isnan(x)

Parameter Description:

Return Value

Returns a Boolean; True if the number is NaN (not a number), otherwise False.

Example

The following example checks whether a number is NaN (not a number:

Example

Import the math package

import

math

Check whether a number is NaN

print

(

math

.

isnan

(

56

)

)

print

(

math

.

isnan

(

45.34

)

)

print

(

math

.

isnan

(

45.34

)

)

print

(

math

.

isnan

(

math

.

inf

)

)

print

(

math

.

isnan

(

float

(

"nan"

)

)

)

print

(

math

.

isnan

(

float

(

"inf"

)

)

)

print

(

math

.

isnan

(

float

(

"-inf"

)

)

)

print

(

math

.

isnan

(

math

.

nan

)

)

Output result:



False

False

False

False

True

False

False

True

Python math Module Python math Module