分析家 发表于 2018-8-15 11:16:26

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.
  说明:

[*]  返回数字的绝对值,参数可以是整数、浮点数或者复数
  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
页: [1]
查看完整版本: python内置函数1-abs()