Python3 abs() Function
Description
The abs() function returns the absolute value of a number.
Syntax
The following is the syntax of the abs() method:
abs( x )
Parameters
- x -- A numeric expression, which can be an integer, a floating-point number, or a 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 an example of using the abs() method:
Example
#!/usr/bin/python3
print ("abs(-40) : ", abs(-40))
print ("abs(100.10) : ", abs(100.10))
print ("abs(-40) : ", abs(-40))
print ("abs(100.10) : ", abs(100.10))
After running the above example, the output result is:
abs(-40) : 40 abs(100.10) : 100.1
Related articles:Difference between Python fabs() and abs()
Other Extensions
Python3 Numbers