首页 > 代码库 > python内置函数1-abs()

python内置函数1-abs()

Help on built-in function abs in module __builtin__:


abs(...)

    abs(number) -> number

    

    Return the absolute value of the argument.

abs(x)

Return the absolute value of a number. The argument may be a plain or long integer or a floating point number. If the argument is a complex number, its magnitude is returned.


说明:

  1. 返回数字的绝对值,参数可以是整数、浮点数或者复数

 2. 如果参数是一个复数,此方法返回此复数的绝对值(此复数与它的共轭复数的乘积的平方根)


>>> abs(5)

5

>>> abs(-3)

3

>>> abs(0)

0

>>> abs(7.1415)

7.1415

>>> abs(-7.1415)

7.1415

>>> a=complex(3,4)

>>> a

(3+4j)

>>> abs(a)

5.0

>>> b=complex(-2,-8)

>>> b

(-2-8j)

>>> abs(b)

8.246211251235321



本文出自 “大云技术” 博客,请务必保留此出处http://hdlptz.blog.51cto.com/12553181/1897524

python内置函数1-abs()