abs()为python内置函数,可直接调用
abs()的函数描述: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.即:abs()函数可返回一个数的绝对值,()中参数可以是整数或浮点数,如果参数是复数,则返回这个复数的模


下面看下例程
Pycharm下代码:
a = -3
b = -4.5
c = -3 + 4j
print(abs(a))
print(abs(b))
print(abs(c))


输出结果
3
4.5
5.0

更多推荐

python内置函数abs()使用方法