# The difference between ABS () and Math.fabs () in Python

Source: Internet
Author: User

Description: The method in Python `fabs(x)` Returns the absolute value of x . Although similar to `abs()` a function, the following differences exist between the two functions:

• `abs()`is a built-in function that is `fabs()` defined in a `math` module.
• The `fabs()` function is only available for float and integer types, and `abs()` also for complex numbers .
• ABS () return is float and int type, math.fabs () return is float type

Syntax: here is `fabs()` the syntax for the method:

`Import Mathmath.fabs (x)`

Note: This module cannot be accessed directly, requires calling `math` the module, and then `math` calls this function with a static object.

Parameters x is the incoming parameter.

return value The absolute value of the returned x .

Example

`Import MathA =-1b =-1.3232c = bD = 1+1.0jE = 3+4.0jf =-230.13000Print ("ABS () absolute value of output a:", ABS (a))Print ("fabs () absolute value of output a", Math.fabs (a))Print ("ABS () absolute value of output B:", ABS (b))Print ("absolute value of output C:", Math.fabs (c))Print ("absolute value of output D:", ABS (d))Print ("absolute value of output e:", ABS (E))# Print ("fabs () output e absolute value:", Math.fabs (e))Print ("abs () output F absolute value:", ABS (f))Print (the absolute value of the "fabs () output F:", Math.fabs (f))`

Output

`ABS () absolute value of output a: 1Fabs () absolute value of output a 1.0ABS () absolute value of output B: 1.3232Absolute value of output C: 1.3232Absolute value of output D: 1.4142135623730951Absolute value of output E: 5.0ABS () absolute value of output F: 230.13Fabs () absolute value of output F: 230.13`

The difference between ABS () and Math.fabs () in Python

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.