英文文檔:
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
說明:
1. 返回數字的絕對值,參數可以是整數、浮點數或者復數
2. 如果參數是一個復數,此方法返回此復數的絕對值(此復數與它的共軛復數的乘積的平方根)
示例:
>>> help(abs) Help on built-in function abs in module builtins: abs(x, /) Return the absolute value of the argument. >>> abs(2)#正整數 2 >>> abs(-2)#負整數 2 >>> abs(0)#0 0 >>> abs(2.3)#正浮點數 2.3 >>> abs(-2.3)#負浮點數 2.3 >>> c1 = complex(1,1) >>> c1 #復數 (1+1j) >>> abs(c1) #復數絕對值 1.4142135623730951 >>> c2 = complex(-1,-1) >>> c2 #復數 (-1-1j) >>> abs(c2) #復數絕對值 1.4142135623730951 >>>
