python absolute value

Posted by w3diy - 6 months ago

Example 1: Get absolute value of a number

# random integer
integer = -20
print('Absolute value of -20 is:', abs(integer))

#random floating number
floating = -30.33
print('Absolute value of -30.33 is:', abs(floating))    

Get magnitude of a complex number

# random complex number
complex = (3 - 4j)
print('Magnitude of 3 - 4j is:', abs(complex))