make negative number positive python code example
Example 1: convert negative to positive in python
>>> n = -42
>>> -n # if you know n is negative
42
>>> abs(n) # for any n
42
>>> abs(-5.05)
5.05
Example 2: get random number positive or negative python
import random
return 1 if random.random() < 0.5 else -1
Example 3: python convert any number in positive
a = abs(-1)
return a
#returns 1
Example 4: command in python to make negative number positive
abs(x) #x is the integer wish to make positive