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)


暂无数据
推荐帖子
0条评论
0条评论
0条评论