Latest web development tutorials

Python fabs () function

Python figures Python figures


description

fabs () method returns the number of absolute value, such as math.fabs (-10) returns 10.0.


grammar

The following is the syntax fabs () method:

import math

math.fabs( x )

Note: fabs () is not directly accessible, you need to import math module, invoke the method through static object.


parameter

  • x - numeric expression.

return value

Returns the absolute value of the number.

Examples

The following shows an example of the use of fabs () method:

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

After running the above example output is:

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 figures Python figures