One of the reasons for the popularity of Python is its built-in functions. Python provides a large number of built-in functions. The is an absolute value function to find the Python abs Function of any number. While working with distance calculations we always need a positive number. As distance is always positive. Another example of the usage of absolute values is speed calculations. Let’s take a look at how to use the Python abs Function.
|x = -9|
The output is shown below.
The take a look at the distance formula. If we take the absolute value of the difference then we
Don’t need to take the square and then square root.
|point1 = [4, 0]point2 = [6, 6]dist = ((point1-point2))+((point1-point2))print(dist)|
The output is as follows.
Complex number examples
To find the magnitude of a complex number absolute value function can be used. Let’s take a look at an example.
|complex_num = 5 – 5j|
complex_num2 = 7 + 4j