Python math.copysign() Method
Python math.copysign(x,y) The method returns a floating-point number based on the absolute value of x and the sign +/- of y.
Python version: 2.6
Syntax
The syntax of the math.copysign() method is as follows:
math.copysign(x, y)
Parameter Description:
- x -- required, a number.
- y -- required, a number; the returned value takes the sign +/- of this argument.
Return Value
Returns a floating-point value composed of the value of the first argument and the sign of the second argument.
Example
The following example returns the value of the first argument and the sign of the second argument:
Example
Import the math package
import
math
Return the value of the first argument and the sign of the second argument
(
math
.
copysign
(
4
,
1
)
)
(
math
.
copysign
(
8
,
97.21
)
)
(
math
.
copysign
(
43
,
76
)
)
Output result:
-4.0
8.0
-43.0
Python math Module