首页 > 编程语言 > 详细

python内置函数1-abs()

时间:2017-02-14 22:59:47      阅读:353      评论:0      收藏:0      [点我收藏+]

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()

原文:http://hdlptz.blog.51cto.com/12553181/1897524

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!