The World Wide Web, restored to 800 pixels of glory.
GeezerVison is showing www.runoob.com — Python abs() 函数 | 菜鸟教程
Python 数字
abs() 函数返回数字的绝对值。
以下是 abs() 方法的语法:
abs( x )
以下展示了使用 abs() 方法的实例:
以上实例运行后输出结果为:
abs(-45) : 45 abs(100.12) : 100.12 abs(119L) : 119
cloudray
clo***[email protected]
若参数为复数,则返回复数的绝对值(此复数与它的共轭复数的乘积的平方根),就是 (a^2+b^2) 开根。
>>> abs(1+2j) 2.23606797749979 >>> abs(1+1j) 1.4142135623730951 >>> abs(1j) 1.0
取消