diff --git a/guide/english/python/abs-function/index.md b/guide/english/python/abs-function/index.md index 318ea81c42..8fbbbc39ff 100644 --- a/guide/english/python/abs-function/index.md +++ b/guide/english/python/abs-function/index.md @@ -1,24 +1,29 @@ --- title: Python Abs Function --- -`abs()` is a built-in function in Python 3, to compute the absolute value of any number. The absolute value of a number "means only how far a number is from 0" 1 It takes one argument `x`. The argument can even be a complex number, and in that case its modulus is returned. +`abs()` is a built-in function in Python 3, to compute the absolute value of any number. The absolute value of a number "means only how far a number is from 0" 1 It takes one argument `x`. The argument can even be a complex number, or a mathematical expression. ## Argument -It takes one argument `x` - an integer, or decimal, or a complex number. +It takes one argument `x` - either an integer, or decimal, or complex number, or any mathematical expression in general. ## Return Value The return value would be a positive number or zero. Even if a complex number is passed, it would return its magnitude, computed as per complex number algebra. ++ A complex number is passed - It would return its modulus i.e., magnitude, computed as per complex number algebra. ++ A mathematical expression is passed - It would return its `|result|`, computed as per BODMAS rule. ## Code Sample ```python print(abs(3.4)) # prints 3.4 print(abs(-6)) # prints 6 print(abs(3 + 4j)) # prints 5.0, because |3 + 4j| = 5 +print(abs(3 + 4 - 6 * 3.4)) # prints 13.4, because |3 + 4 - (6 * 3.4)| = |3 + 4 - 20.4| = |-13.4| = 13.4 +print(abs(3 - 4j - 3 - 4j)) # prints 8.0, because |(3 - 3) + (- 4j - 4j)| = 8.0 ``` -🚀 Run Code +🚀 Run Code + Official Docs