- copysign() is a python math function which are able to change the sign of the numeric values.
Syntax-
math.copysign(num1,num2)
-Here copysign() takes two argument both are number, it can be positive or negative both.
-It return the float num1 with the sign of num2.
Example-
num1 is 4
num2 is -n
copysign(num1,num2) will return -4
num1 is -4
num2 is n
copysign(num1,num2) will return 4
program-
import math
a=4
b=-1
n=math.copysign(a,b)
print(n)
print(math.copysign(3,-2))
print(math.copysign(-3,-2))
print(math.copysign(-3,2))
print(math.copysign(3,2))
-4.0
-3.0
-3.0
3.0
3.0
import math
print(math.copysign(3,0))
print(math.copysign(0,-2))
3.0
-0.0