The abs() method in Python Numbers returns the absolute value of x. Here x is a positive value that represents the distance between x and zero. One is supposed to provide the input value to abs() in order to get the absolute value in return. This number given can be ab integer, a complex number, or afloat. In case x is a complex number then abs() method in Python number returns the magnitude. The abs() method in Python number takes over one argument i.e. the value you wish to get absolute.
Following is the syntax for abs() method:
abs( x )
x - This is a numeric expression.
This method returns the absolute value of x.
The following example shows the usage of the abs() method.
#!/usr/bin/python print "abs(-45) : ", abs(-45) print "abs(100.12) : ", abs(100.12) print "abs(119L) : ", abs(119L)
When we run the above program, it produces the following result:
abs(-45) : 45 abs(100.12) : 100.12 abs(119L) : 119
Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.