Python-number-fabs

提供:Dev Guides
移動先:案内検索

Python Number fabs()メソッド

説明

Pythonの数値メソッド* fabs()*は、xの絶対値を返します。

構文

以下は* fabs()*メソッドの構文です-

import math

math.fabs( x )

-この関数は直接アクセスできないため、数学モジュールをインポートしてから、数学静的オブジェクトを使用してこの関数を呼び出す必要があります。

パラメーター

  • x -これは数値です。

戻り値

このメソッドは、xの絶対値を返します。

次の例は、fabs()メソッドの使用法を示しています。

#!/usr/bin/python
import math   # This will import math module

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)

上記のプログラムを実行すると、次の結果が生成されます-

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