Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python math.copysign() Method

Python math.copysign() Method

Python math Module Python math Module

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:

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

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 math Module