Python math.copysign() Method
Example
Return the value of the first parameter and the sign of the second parameter:
#Import math Library
import math
#Return the value of the first
parameter and the sign of the second parameter
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 |
y | Required. A number. The return will have the sign (+/-) of this parameter |
Technical Details
Return Value: | A float value, which consists of
the value of first parameter, and sign of the second parameter |
---|---|
Python Version: | 2.6 |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.