Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The Python Math copysign() function is used to return a number with magnitude of first argument and sign of second argument.

Syntax

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 below example, copysign() function is used to return 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