The Python CopySign function is one of the Python Math function which is used to find the absolute value of first argument and return the absolute value along with sign specified in second argument. In this article we will show you, How to use CopySign() function in Python Programming language with example.

## Syntax of a Python CopySign Function

The basic syntax of the CopySign Function in Python Programming Language is as shown below:

Math.copysign(x, y);

**X:**Please specify the X value here. CopySign() Function will find the absolute value of this argument.**Y:**Please specify the X value here. CopySign() Function will use this arguments sign (Positive or Negative) and returns the output.

For example, if **x** = 2.45 and **Y** = -5.40 then, Math.copysign(2.45, -5.40) = -2.45. This is because absolute value of 2.45 is 2.45 and the second argument sign is Negative so, output is -2.45

**NOTE: **If the *X value* or Y* value* argument is not a number, CopySign() function will return * TypeError*.

### Python CopySign Function Example

The Python CopySign function is used to return the absolute value of first argument along with sign specified in second argument. In this example, We are going to find the same of different data types and display the output

**PYTHON CODE**

# Python COPYSIGN Function import math Tup = (10.98, 20.26, 12.05, -40.95 , 50.45) # Tuple Declaration Lis = [-10.98, 32.65, -39.59, -42.15 , 15.97] # List Declaration print('Calculating CopySign of Positive Number = %.2f' %math.copysign(2, 3)) print('Calculating CopySign of Negative Number = %.2f' %math.copysign(-2, 3)) print('Calculating CopySign of Positive Decimal = %.2f' %math.copysign(5.63, -3.0)) print('Calculating CopySign of Negative Decimal = %.2f' %math.copysign(-2.48, 1.15)) print('Calculating Power of of Tuple Item = %.2f' %math.copysign(Tup[2], 2.25)) print('Calculating Power of of Tuple Item = %.2f' %math.copysign(Tup[2], -2.25)) print('Calculating Power of List Item = %.2f' %math.copysign(Lis[4], 4.5)) print('Calculating Power of List Item = %.2f' %math.copysign(Lis[4], -4.5)) print('Calculating CopySign of Multiple Number = %.2f' %math.copysign(1 + 2 - 12.65, 2)) print('Calculating CopySign of String Value = ', math.copysign('2', 3))

**OUTPUT**

**ANALYSIS**

- At the beginning, We declared Python List and Tuple with some random values.
- Within the first two statements, We passed both the Positive integer and negative integer as the CopySign() Function arguments. From the above screenshot you can observe that, CopySign() Function is returning output.
- Within the next two statements, We passed both the Positive and negative decimal values as the CopySign() Function arguments. From the above screenshot you can observe that, CopySign() Function is returning output.
- Next four statements, We used the Python Tuple and List items as first arguments and Positive and negative decimal values as second argument for CopySign() Function. If you observe the above screenshot, CopySign() function is working perfectly on them.
- Next statement, We assigned multiple values as the first arguments and the CopySign() Function worked without any issue.
- Last, We tried CopySign() Function on String value. As we said before, this will return
as output**TypeError**

Thank You for Visiting Our Blog