Python math - copysign() Function
The Python math.copysign() function returns a number with magnitude of first argument and sign of second argument.
Syntax
math.copysign(magnitude, sign)
Parameters
magnitude |
Required. Specify a value providing the magnitude of the result. |
sign |
Required. Specify a value providing the sign of the result. |
Return Value
Returns a number with magnitude of first argument and sign of second argument.
Example:
In the example below, copysign() function returns a number with magnitude of first argument and sign of second argument.
import math print(math.copysign(-324.1, 4)) print(math.copysign(500, -21)) print(math.copysign(-40.2, -15))
The output of the above code will be:
324.1 -500.0 -40.2
❮ Python Math Module