Home >>Python math Module >Python math.copysign() Method
Python math.copysign() Method returns a float value of the first parameter and the sign(+/-) of the second parameter and it accepts two numbers (floats or integer).
Syntax:math.copysign(x, y)
Parameter | Description |
---|---|
x | It is Required to be a number converted. It will show a TypeError, if x is not a number |
y | It is required a number will return the sign (+/-) of parameter |
import math
print(math.copysign(2, 1))
print(math.copysign(-5, 35.18))
print(math.copysign(-67, -23))
import math
x = -32
y = 8
print("copysign(x,y): ", math.copysign(x,y))
x = -32
y = -8
print("copysign(x,y): ", math.copysign(x,y))
x = 32.16
y = -8
print("copysign(x,y): ", math.copysign(x,y))
x = -32.64
y = -8.64
print("copysign(x,y): ", math.copysign(x,y))
x = -32
y = 8
print("copysign(x,y): ", math.copysign(x,y))