Home >>Python math Module >Python math.copysign() Method

Python math.copysign() Method

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 Values

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
Here is an example of Python math.copysign() Method:

import math  
print(math.copysign(2, 1))
print(math.copysign(-5, 35.18))
print(math.copysign(-67, -23))

Output:
2.0
5.0
-67.0
Example 2:

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))

Output:
copysign(x,y): 32.0
copysign(x,y): -32.0
copysign(x,y): -32.16
copysign(x,y): -32.64
copysign(x,y): 32.0

No Sidebar ads