Latest web development tutorials

fabs Python function ()

figure Python figure Python


descrizione

fabs () restituisce il numero di valore assoluto, come math.fabs (-10) restituisce 10.0.


grammatica

La seguente è la sintassi fabbriche () metodo:

import math

math.fabs( x )

Nota: fab () non è direttamente accessibile, è necessario importare il modulo per la matematica, richiamare il metodo attraverso oggetto statico.


parametri

  • x - espressione numerica.

Valore di ritorno

Restituisce il valore assoluto del numero.

Esempi

Quanto segue mostra un esempio dell'uso di fabs () Metodo:

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import math   # 导入数学模块

print "math.fabs(-45.17) : ", math.fabs(-45.17)
print "math.fabs(100.12) : ", math.fabs(100.12)
print "math.fabs(100.72) : ", math.fabs(100.72)
print "math.fabs(119L) : ", math.fabs(119L)
print "math.fabs(math.pi) : ", math.fabs(math.pi)

Dopo aver eseguito l'output sopra esempio è:

math.fabs(-45.17) :  45.17
math.fabs(100.12) :  100.12
math.fabs(100.72) :  100.72
math.fabs(119L) :  119.0
math.fabs(math.pi) :  3.14159265359

figure Python figure Python