The math.copysign() function returns a float with the magnitude (absolute value) of the first argument and the sign of the second argument.

math.copysign(x, y)

Where x is a numeric value (can be a float or an integer) and y is the sign value, which can be an integer or float, positive or negative.

The function returns the absolute value of x with the sign of y.

import math 

print(math.copysign(2, 2))
print(math.copysign(2, -5))
print(math.copysign(-5, 2))
print(math.copysign(-5, -2))
print(math.copysign(0.5, -2))