Patrick Patrick - 4 years ago 431
Python Question

How to convert a negative number to positive?

How can I convert a negative number to positive in Python? (And keep a positive one.)

Answer Source
>>> n = -42
>>> -n       # if you know n is negative
42
>>> abs(n)   # for any n
42

Don't forget to check the docs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download