Méthode math.isnan() de Python

Python math 模块Module math de Python

Python math.isnan()La méthode détermine si un nombre est NaN (pas un nombre). Si le nombre est NaN (pas un nombre), elle renvoie True, sinon elle renvoie False.

Version de Python : 3.5

Syntaxe

La syntaxe de la méthode math.isnan() est la suivante :

math.isnan(x)

Description du paramètre :

  • x-- Obligatoire, nombre. Si x n'est pas un nombre, renvoie TypeError.

Valeur de retour

Renvoie une valeur booléenne. Renvoie True si le nombre est NaN (pas un nombre), sinon renvoie False.

Exemples

L'exemple suivant vérifie si un nombre est NaN (pas un nombre :

Exemples

# Importer le package math
import math

# Vérifier si le nombre est 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))

Sortie :

False
False
False
False
True
False
False
True

Python math 模块Module math de Python

Autres extensions