24
loading...
This website collects cookies to deliver better user experience
abs()
function in Python returns the absolute value of a given number, which means the abs()
method removes the negative sign of a number. abs()
function will return its magnitude.abs()
method is abs()
function takes a single argument, a number whose absolute value is to be returned. The number can be abs()
method returns an absolute value of a given number.abs()
function will turn any negative number into positive, the absolute value of a negative number is multiplied by (-1) and returns the positive number, and the absolute value of a positive number is the number itself. abs()
function, and returns the absolute value.# Python code to illustrate abs() built-in function
# integer number
integer = -10
print('Absolute value of -10 is:', abs(integer))
# positive integer number
positive_integer =20
print('Absolute value of 20 is:', abs(positive_integer))
# floating point number
floating = -33.33
print('Absolute value of -33.33 is:', abs(floating))
Absolute value of -10 is: 10
Absolute value of 20 is: 20
Absolute value of -33.33 is: 33.33
Absolute value of 3-4j is: 5.0
abs()
function and returns the absolute value.# Python code to illustrate abs() built-in function
# complex number
complex=(3-4j)
print('Absolute value of 3-4j is:', abs(complex))
Absolute value of 3-4j is: 5.0