python内置函数每日一学 -- abs()

abs(x)

官方文档解释:

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

详解:

  返回数字的绝对值。参数可以是整数或浮点数。如果参数是复数,则返回其大小。

实例:

1 print(abs(-2.88))         # 2.88
2 print(abs(2.88))          # 2.88
3 print(abs(-1))             # 1
4 print(abs(1))              # 1

猜你喜欢

转载自www.cnblogs.com/YD2018/p/9281710.html
ABS
今日推荐