DEV Community

Arun kumar G
Arun kumar G

Posted on

Python - Built-in functions - abs()

Summarizing my learnings in Python3. Starts with Python Built in functions with examples.

abs() --> Absolute value

1,Integers and float

abs function will the absolute value of the given number. for example, if we provide a negative number, it will return the positive number which is the absolute one.

Code:
x=-7.67
print(f"the absolute value of -7.67 is {abs(x)}

Output:
the absolute value of -7.67 is 7.67

2,Complex number
If we use abs function for complex number. This function will return the answer based on the below formula,

Formula: a+bj = Square root (a^2 +b^2)

Code:
x=1+1j
print(f"the absolute value of 1+1j is {abs(x)}")

Output:
the absolute value of 1+1j is 1.414

Top comments (0)