Python built-in functions (1) -- abs, python built-in functions abs
English document:
Abs (X)
Return the absolute value of a number. The argument may be an integer or a floating point number. If the argument is a complex number, its magnitude is returned
Note:
1. Return the absolute value of a number. The parameter can be an integer, floating point, or plural number.
2. If the parameter is a plural number, this method returns the absolute value of this plural number (the square root of the product of this plural number and Its Bounded plural number)
Example:
>>> Help (abs) Help on built-in function abs in module builtins: abs (x,/) Return the absolute value of the argument. >>> abs (2) # positive integer 2 >>> abs (-2) # negative integer 2 >>> abs (0) #00 >>> abs (2.3) # Positive floating point number 2.3 >>> abs (-2.3) # negative floating point number 2.3 >>>> c1 = complex () >>> c1 # plural (1 + 1j) >>> abs (c1) # absolute value of the plural number 1.4142135623730951 >>>> c2 = complex (-1,-1) >>>> c2 # plural (-1-1j) >>> abs (c2) # the absolute value of the plural is 1.4142135623730951 >>>