码迷,mamicode.com
首页 > 编程语言 > 详细

python内置函数1-abs()

时间:2017-02-14 23:00:04      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:python   number   function   absolute   complex   

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

标签:python   number   function   absolute   complex   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!