How to calculate absolute value in Python?

PythonServer Side ProgrammingProgramming

The abs() function of Python's standard library returns the absolute value of the given number. Absolute value of a number is the value without considering its sign. Hence absolute of 10 is 10, -10 is also 10. If the number is a complex number, abs() returns its magnitude.

Example

>>> abs(11.11)
11.11
>>> abs(-11.11)
11.11
>>> abs(2+3j)
3.605551275463989
>>> abs(3-6j)
6.708203932499369
>>> abs(3-4j)
5.0
raja
Published on 24-Feb-2018 06:14:43
Advertisements