Learn and Learn

Learn And Learn - great place for tutorials, references and how-to

Python copysign() Function

Python copysign(x,y) function exists in Standard math Library of Python Programming Language. This function returns a float value consisting of magnitude from parameter x and the sign (+ve or -ve) from parameter y. This means the sign (+ve or -ve) of parameter y is attached to the magnitude of parameter x. For example if:

For example if:

Parameter x = 3
Parameter y = -2
The return value will be: -3.0

Here 3 is taken from parameter x and –ve sign is taken from parameter y. In return, a float -3.0 is returned. In this reference, copysign() function will further be elaborated from a programming perspective.

Python copysign() Function Syntax:

The syntax of copysign(x,y) function in Python is:

math.copysign( x , y )

 

Python copysign() Function Parameters:

x is any valid Python number. This parameter is required.
y any valid Python number. This parameter is required.
Note: In copysign() function, both of the parameters are required.

 

Python copysign() Function Compatibility

Python 2.x – Yes
Python 3.x – Yes

 

Python copysign() Function Return Value:

This function will return a float value which is consist of the absolute value or the magnitude of the parameter x and the sign of parameter y.

 

Python copysign() Function Example:


Output of Python copysign() function:

4.0
-4.0

Loading...
LearnAndLearn.com © 2018 - All rights reserved