Python math.copysign() Method
Example
Use the sign (+/-) of the second value, for the number of the first value:
#Import math Library
import math
#Return the first value, with
the sign of the second value
print(math.copysign(4, -1))
print(math.copysign(-8, 97.21))
print(math.copysign(-43, -76))
Try it Yourself »
Definition and Usage
The math.copysign()
method returns a float consisting of the value of the first parameter and the sign(+/-) of the second parameter.
Syntax
math.copysign(x, y)
Parameter Values
Parameter | Description |
---|---|
x | Required. A number. The return will have the value of this parameter. It must be a number otherwise it will produce a TypeError |
y | Required. A number. The return will have the sign (+/-) of this parameter. It must be a number otherwise it will produce a TypeError |
Technical Details
Return Value: | A float value. This will have the value of first parameter, and sign of second parameter |
---|---|
Python Version: | 2.6 |