Python abs() Built in Function

The abs() function in Python returns the absolute value of a number. The absolute value of a number is its distance from zero on the number line. For example, the absolute value of -5 is 5 and the absolute value of 5 is also 5. The abs() function can take any numeric type as an argument, such as integers, floats or complex numbers. If the argument is a complex number, abs() returns its magnitude, which is the square root of the sum of squares of its real and imaginary parts.

Here are some examples of Python code using abs():


# Absolute value of an integer

print(abs(-10)) # prints 10

# Absolute value of a float
print(abs(-3.14)) # prints 3.14

# Absolute value of a complex number
print(abs(2+3j)) # prints 3.605551275463989

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Stock Market Predictions with LSTM in Python

Collections In Python

Python Count Occurrence Of Elements

Python One Liner Functions