YouTip LogoYouTip

Python3 Func Number Fabs

# Python3.x Python3 fabs() Function [![Image 3: Python3 Numbers](#) Python3 Numbers](#) * * * ## Description The fabs() method returns the absolute value of a number as a floating-point number, e.g., math.fabs(-10) returns 10.0. The fabs() function is similar to the abs() function, but it has two differences: * abs() is a built-in function. The fabs() function is defined in the math module. * The fabs() function is only effective for floating-point and integer values. abs() can also be used with complex numbers. * * * ## Syntax Here is the syntax for the fabs() method: import math math.fabs( x ) **Note:** fabs() cannot be accessed directly; you need to import the math module and call the method via a static object. * * * ## Parameters * x -- A numeric expression, which can be an integer, float, etc. The function returns the absolute value of x, i.e., a non-negative number. * * * ## Return Value Returns the absolute value of the number. * * * ## Examples The following examples demonstrate the use of the fabs() method: ## Example 1 import math x = -1.5 y =math.fabs(x) print(y)# Output 1.5 x =10 y =math.fabs(x) print(y)# Output 10.0 In the above example, fabs(-1.5) returns the absolute value of -1.5, which is 1.5, and fabs(10) returns the absolute value of 10, which is 10.0. Note that the return value is always a floating-point number, even if the input parameter is an integer. The output of the above example is: 1.510.0 ## Example 2 #!/usr/bin/python3 import math# Import the math module print("math.fabs(-45.17) : ",math.fabs(-45.17)) print("math.fabs(100.12) : ",math.fabs(100.12)) print("math.fabs(100.72) : ",math.fabs(100.72)) print("math.fabs(math.pi) : ",math.fabs(math.pi)) The output of the above example is: math.fabs(-45.17) : 45.17 math.fabs(100.12) : 100.12 math.fabs(100.72) : 100.72 math.fabs(math.pi) : 3.141592653589793 [![Image 4: Python3 Numbers](#) Python3 Numbers](#)
← R Mysql ConnectR Input Xml File β†’