Python abs() built-in function
Python abs() built-in function
From the Python 3 documentation Return the absolute value of a number. The argument may be an integer, a floating point number, or an object implementing abs()
. If the argument is a complex number, its magnitude is returned.
>>> abs(-1)
# 1
>>> abs(0)
# 0
>>> abs(1)
# 1
>>> abs(3.14)
# 3.14
>>> abs(3 + 2j)
# 3.6055512754639896
>>> abs(0x10)
# 16
>>> abs(0b10)
# 2
>>> abs(0o20)
# 16