Méthode math.isinf() de Python

Python math 模块Module math de Python

Python math.isinf()La méthode détermine si x est infini. Renvoie True si x est l'infini positif ou négatif, sinon renvoie False.

Version de Python : 2.6

Syntaxe

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

math.isinf(x)

Description des paramètres :

  • x-- Requis, un nombre. Renvoie TypeError si x n'est pas un nombre.

Valeur de retour

Renvoie une valeur booléenne. Renvoie True si x est l'infini positif ou négatif, sinon renvoie False.

Exemple

L'exemple suivant vérifie si un nombre est infini :

Exemple

# Importer le package math
import math

# Vérifier si le nombre est infini
print(math.isinf(56))
print(math.isinf(-45.34))
print(math.isinf(+45.34))
print(math.isinf(math.inf))
print(math.isinf(float("nan")))
print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(-math.inf))

Résultat de sortie :

False
False
False
True
False
True
True
True

Python math 模块Module math de Python

Autres extensions