Python3 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, which can be an integer, float, or complex number.
Return Value
The function returns the absolute value of x (a number); if the argument is a complex number, it returns its magnitude.
Example
The following shows examples of using the abs() method:
Example
#!/usr/bin/python3
(
"abs(-40) : "
,
abs
(
40
)
)
(
"abs(100.10) : "
,
abs
(
100.10
)
)
Running the example above produces:
abs(-40) : 40
abs(100.10) : 100.1
Related articles:Difference between Python fabs() and abs()
Python3 Numbers