Ads by ProfitSence
Close

Absolute Value Function in Python

Last Updated on Wednesday 5th Oct 2022

The abs() function returns the absolute or value of input passed over it as an argument & returns value with no sign consideration.

Python Absolute Value

  • It kind of working similar to the way that you understand mathematics. -Essentially an Absolute number or value is the distance on numbers from 0

Python Abs() Function

  • Is one of the math functions Get the Absolute Value in Python

    			
    					# Get the Absolute Value
    abs(x)
    
    			
    	

Let's take a look at some of the arguments that the absolute function allows.

  • Abs(Integer)``(-1,0,1)
  • Abs(Floating Point Value)``(-1.0,0,1.0)
  • Abs(Complex Numbers)``(5j,0+6j)
			
					num1 = 1
print("Value1",abs(num1))
num2 = -1
print("Value2",abs(num2))
num3 = 5.0
print("Value3",abs(num3))
num4 = -5.0
print("Value4",abs(num4))
num5 = 0-4j
print("Value5",abs(num5))
num6 = 0+8j
print("Value6",abs(num6))

			
	

returns

			
					Value1 : 1
Value2 : 1
Value3 : 5.0
Value4 : 5.0
Value5 : 4.0
Value6 : 8.0

			
	

Python math fabs()

  • Import Math module & use the fabs() method
  • Get the absolute Value as a Float
			
					import math
math.fabs(-55)

			
	

returns

			
					55.0

			
	

Note that fabs() function to get absolute value results in float number