-
Notifications
You must be signed in to change notification settings - Fork 2
Python Function ABS
abs()
is a built-in function in Python 3, to compute the absolute value of any number. It takes one argument x
. The argument can even be a complex number, and in that case its modulus is returned.
It takes one argument x
- an integer, or decimal, or a complex number.
The return value would be a positive number. Even if complex number is passed, it would return its magnitude, computed as per complex number algebra.
print(abs(3.4)) # prints 3.4
print(abs(-6)) # prints 6
print(abs(3 + 4j)) # prints 5, because |3 + 4j| = 5
🚀 Run Code
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links