Python - abs()

The abs() returns absolute value of a number without considering its sign. In other words, absolute value of a number will always return a positive number. The function can have any numeric object as parameter. If it is a complex number, its magnitude is returned. (Magnitude of a+bjis a2+b2)

>>>abs(-10)
10
>>>abs('10')
>>>abs(-1.5)
1.5
>>>abs(1+2j)
2.23606797749979 #this is 5

Learn Python using coding questions with answers.

Python Questions & Answers

Want to check how much you know Python?

Start Python Skill Test