Python math.isnan() Method (2024)

❮ Math Methods

Example

Check whether a value is NaN or not:

# Import math Library
import math

# Check whether some values are NaN or not
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))

Try it Yourself »

Definition and Usage

The math.isnan() method checks whether a value is NaN (Not a Number), or not.

This method returns True if the specified value is a NaN, otherwise it returns False.

Syntax

math.isnan(x)

Parameter Values

Parameter Description
x Required. The value to check

Technical Details

Return Value: A bool value, True if the value is NaN, otherwise False
Python Version: 3.5

❮ Math Methods

Python math.isnan() Method (2024)
Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 6289

Rating: 4.9 / 5 (49 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.