ExampleEdit & Run

Use the abs() function

#with integers
print(abs(-10))
#with floating point values
print(abs(2.5))
#with complex numbers
print(abs(4 + 3j))
copy
Output:
10 2.5 5.0 [Finished in 0.010449925903230906s]

The builtin abs() function returns the absolute value of a number. 

The function takes only one argument i.e the number which we want to get the absolute value of.

Syntax:
abs(num)
copy

It supports all the numerical data types such as integers, floats and complex numbers.  For integers and the floating point numbers; the absolute value is the distance between that number and zero on a number line. It is the magnitude or size of the number without regard to its sign.

The absolute value of a positive number is the number itself while the absolute value of a negative number is its positive counterpart. For example, the absolute value of 3 is 3, and the absolute value of -3 is also 3.

ExampleEdit & Run
print( abs(6) )
print( abs(-7) )
print( abs(3.5) )
print( abs(-9.1) )
print( abs(-0.01) )
copy
Output:
6 7 3.5 9.1 0.01 [Finished in 0.0101801548153162s]

For complex numbers;  the absolute value is the distance from the origin (0,0) to the point (a,b) in the complex plane. This value is calculated using the Pythagorean theorem, for example the absolute value of 3 + 4j is 5.

The function returns a float value.

ExampleEdit & Run
print( abs(3 + 4j) )
print( abs(-6 + 8j) )
print( abs(12 +9j) )
print( abs(7 + 6j) )
print( abs(-5 + 5j) )
copy
Output:
5.0 10.0 15.0 9.219544457292887 7.0710678118654755 [Finished in 0.009866786189377308s]