Latest web development tutorials

Pythonのファブ()関数

Pythonの数値 Pythonの数値


説明

ファブ()メソッドは(-10)10.0を返すなどmath.fabsとして、絶対値の数を返します。


文法

次の構文ファブ()メソッドです。

import math

math.fabs( x )

注:ファブ()は直接アクセスできません、あなたは数学のモジュールをインポートする必要があり、静的オブジェクトを介してメソッドを呼び出します。


パラメータ

  • X - 数値式。

戻り値

数の絶対値を返します。

以下は、ファブの使用例()メソッドを示しています。

#!/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)

上の例の出力を実行した後です。

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

Pythonの数値 Pythonの数値