热线电话:13121318867

登录
2019-01-17 阅读量: 873
Python中的abs函数

abs()函数用于返回数字的绝对值。
句法:
ABS(数) number:可以是整数,浮点数 数字或复数
abs()只接受一个参数,一个返回绝对值的数字。参数可以是整数,浮点数或复数。

  • 如果参数是整数或浮点数,则abs()返回整数或浮点数的绝对值。
  • 在复数的情况下,abs()仅返回幅度部分,也可以是浮点数。

# Python code to illustrate

# abs() built-in function

# floating point number

float = -54.26

print('Absolute value of integer is:', abs(float))

# An integer

int = -94

print('Absolute value of float is:', abs(int))

# A complex number

complex = (3 - 4j)

print('Absolute value or Magnitude of complex is:', abs(complex))

0.0000
3
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子