Easy Tutorial
❮ Python Iterator Generator Python Att Dictionary Values ❯

Python math.copysign() Method

Python math Module

The math.copysign(x, y) method in Python returns a floating-point number with the absolute value of x and the sign of y +/-.

Python Version: 2.6

Syntax

The syntax for the math.copysign() method is as follows:

math.copysign(x, y)

Parameter Descriptions:

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 with the sign of the second argument:

Example

# Import math package
import math

# Return the value of the first argument with the sign of the second argument
print(math.copysign(4, -1))
print(math.copysign(-8, 97.21))
print(math.copysign(-43, -76))

Output result:

-4.0
8.0
-43.0

Python math Module

❮ Python Iterator Generator Python Att Dictionary Values ❯