Python provides the abs()
function in order to calculate and return the absolute value of the given number. Absolute value is used in mathematics in order to make the calculation easier. The given value can be different types of a number of presentations like float, complex, negative, hexadecimal, etc.
Python提供了abs()
函数,以便计算并返回给定数字的绝对值。 在数学中使用绝对值是为了使计算更容易。 给定值可以是许多表示形式的不同类型,例如浮点数,复数,负数,十六进制等。
abs()函数语法 (abs() Function Syntax)
abs() function has very simple syntax where only a single argument is accepted in order to calculate its absolute value.
abs()函数的语法非常简单,其中仅接受单个参数以计算其绝对值。
abs(NUMBER)
- `abs` is the function name that will return the absolute value of the given NUMBER. “ abs”是函数名称,它将返回给定NUMBER的绝对值。
- `NUMBER`is the number we want to calculate its absolute value. NUMBER can be floating-point, negative numbers, complex numbers, hexadecimal, binary, etc. “ NUMBER”是我们要计算其绝对值的数字。 NUMBER可以是浮点数,负数,复数,十六进制,二进制等。
整数的绝对值 (Absolute Value For A Integer)
We will start with a simple example where we will calculate the absolute value of an integer.
我们将从一个简单的示例开始,在该示例中,我们将计算整数的绝对值。
abs(5)
//Equal to the 5
abs(55)
//Equal to the 55
abs(550)
//Equal to the 550
abs(0)
//Equal to the 0
abs(-5)
//Equal to the 5
abs(-55)
//Equal to the 55
abs(-550)
//Equal to the 550
abs(-999)
//Equal to the 999