Python‎ > ‎Built-in‎ > ‎

abs()


http://www.adilwaseem.com/

Return
The built in function abs() returns the absolute value of the number. Please note that abs is not string function, therefore, it will not bring any absolute value of string.

Syntax
abs(x)

Parameter
x=number

Examples
The method returns the absolute value of the -1.
 >>> abs(-1)
1
>>> 
>>> abs(1)
1
>>>

operator.abs(a)
Return with absolute value.
 >>> import operator
>>> operator.abs(33)
33
>>> operator.abs(-33)
33
>>> operator.abs(0)
0

__abs__ 
Return the same value as operator.abs().
 >>> operator.__abs__(1)
1
>>> operator.__abs__(-1)
1
>>> operator.__abs__(0)
0
>>> 

It also equal to:
 >>> operator.__inv__(abs(-1))
-2

abs(
Return with maximum and minimum degrees values:
import math
import operator

a=math.degrees(33)
b=math.degrees(22)
c=math.degrees(34)
d=math.degrees(13.1)
e=math.degrees(120)

tuple=(a,b,c,d,e)

g=min(tuple)
h=max(tuple)

if operator.truth(abs(g-h)>90):
    print("Minimum degrees value is: ", g)
    print("Maximum degrees value is: ", h)
    print("The difference between minimum and maximum degrees is less 90 Degrees which is: ", abs(g-h))
else:
    print("The difference between minimum and maximum degrees is less 90 Degree which is: ", abs(g-h))

>>> 
Minimum degrees value is:  750.5747116213784
Maximum degrees value is:  6875.493541569878
The difference between minimum and maximum degrees is less 90 Degree which is:  6124.9188299484995
>>> 


Comments