The abs() function in Python returns the absolute value of the given argument. This argument can be an int, a float, or a complex number.
In case of
complexnumbers,abs()function returns the magnitude part only.
The absolute value of a complex number, is defined as the distance between the origin and the point in the complex plane and the formula is:
In case of :
The syntax of abs() function is:
abs(number)
number - Can be an int, a float, or a complex number.Let’s test the abs() function with different inputs:
int_number = -50abs_number = abs(int_number)print(abs_number)
float_number = 50.5abs_number = abs(float_number)print(abs_number)
complex_number = 3-4jabs_number = abs(complex_number)print(abs_number)
Free Resources