Fabs in PythonThe fabs method in Python is used to return the absolute value of a number. It can be used by importing the math module. The math module in Python can be used to implement different basic mathematical operations like addition, subtraction, division, and multiplication. It can also be used to perform calculations involving exponents, logarithms, and trigonometry. SyntaxThe syntax for using fabs in Python is- It’s time to have a look at some programs for a better understanding. Program 1:In the first program, we will discuss the basics of the fabs method. Output: The fabs of a is: 20.3 The fabs of b is: 30.66 The fabs of c is: 19.13 Explanation: Let’s have a look at the explanation of this program-
Program 2:In the next program, we will perform some basic operations on these numbers that involve the usage of fabs(). The following program illustrates the same- Output: The sum of a and b is: -50.96 The sum of b and c is: -11.530000000000001 The sum of d and e is: 50.96 The sum of e and f is: 49.79 Explanation: Let us see what we have done in the above program-
Program 3:Finally, in the last program, we will perform one more mathematical operation on the numbers. Output: The product of a and b is: 622.398 The product of b and c is: -586.5258 The product of d and e is: 622.398 The product of e and f is: 586.5258 Explanation: Let’s have a look at the explanation of this program-
ConclusionIn this Tutorial, we learned fabs() and how they can be used in Python programs to make our work much easier. |
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/263385.html