Python Math Fabs Method

Python Math Fabs

Now, we are going to learn about the fabs method. Using this method, we can get the absolute value of the given argument. So, whenever we are required to get the absolute value for the given argument, we can make use of the fabs method. Let’s have a look at a simple example, which tries to demonstrate the fabs method.

Python Math Fabs

As you can see in the above program, we have imported the math module, and then we are calling the fabs method. We have passed an argument to the fabs method, which is -2.9. So, if you try to execute the above program and try to have a look at the output, you can find that the output comes out to be 2.9, which is the absolute value of the given argument.

Basically, we can say that the absolute value of some number is the distance of that number from the number zero on the number line, without taking the direction into consideration.

So, as and when required, we can simply make use of the fabs method in our python programs. Remember that the fabs method returns the absolute value of the given argument.