Python abs() Function: Complete Guide

The abs function is used to return the absolute value of a number. Its syntax is:

abs(x)

The value of x can be either an integer or a floating point number. If x is a positive number, it will return x itself; if x is a negative number, it will return its absolute value. For example:

print(abs(5))    # 输出 5
print(abs(-5))   # 输出 5
print(abs(-3.14))  # 输出 3.14
bannerAds