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

Syntax:
math.copysign(x, y)
copy

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.

ExampleEdit & Run
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))
copy
Output:
2.0 -2.0 5.0 -5.0 -0.5 [Finished in 0.010776820126920938s]