Python abs() function
Description
The abs() function returns the absolute value of a number.
Syntax
The syntax of the abs() method is as follows:
abs( x )
Parameters
- x -- a numeric expression.
Return Value
The function returns the absolute value of x (a number).
Example
The following shows examples of using the abs() method:
#!/usr/bin/python
"
abs(-45) :
"
,
abs
(
45
)
"
abs(100.12) :
"
,
abs
(
100.12
)
"
abs(119L) :
"
,
abs
(
119L
)
Running the example above produces:
abs(-45) : 45
abs(100.12) : 100.12
abs(119L) : 119
Python Numbers