{"id":24093,"date":"2021-10-14T09:10:20","date_gmt":"2021-10-14T03:40:20","guid":{"rendered":"https:\/\/python-programs.com\/?p=24093"},"modified":"2021-11-05T20:56:52","modified_gmt":"2021-11-05T15:26:52","slug":"python-program-for-copysign-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-copysign-function\/","title":{"rendered":"Python Program for copysign() Function"},"content":{"rendered":"

In the previous article, we have discussed Python Program for ceil() Function<\/a>
\ncopysign() Function in Python:<\/strong><\/p>\n

The math.copysign() method returns a float containing the first parameter’s value and the sign (+\/-) of the second parameter.<\/p>\n

Syntax:<\/strong><\/p>\n

math.copysign(x, y)<\/pre>\n

Parameter Values:<\/strong><\/p>\n

x:<\/strong> This is required. It is a number. It returns the value of this parameter.<\/p>\n

y:<\/strong> This is required. It is a number. It returns the sign(+\/-) of this parameter.<\/p>\n

For example:<\/p>\n

let x=10, y=-20.5<\/p>\n

The math.copysign() method returns the value of x=10, and the sign of y i.e,negative sign(-).<\/p>\n

so, the result number = -10<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given tuple = (1, -10, 20, 35, -12.5)\r\nGiven List = [6.7, 80, -10, -26, 13.5]<\/pre>\n

Output:<\/strong><\/p>\n

The copysign value of given numbers 12 and -10 =  -12.0\r\nThe copysign value of given numbers -9.5 and 30 =  9.5\r\nThe copysign value of given tuple element gvn_tupl[1] and 50 =  10.0\r\nThe copysign value of given list element gvn_lst[2] and -65 =  -10.0<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given tuple = (10, -20, 30, -40, 50)\r\nGiven List = [1, -2, -3, 4]<\/pre>\n

Output:<\/strong><\/p>\n

The copysign value of given numbers 45 and -70 =  -45.0\r\nThe copysign value of given numbers -80 and 100 =  80.0\r\nThe copysign value of given tuple element gvn_tupl[0] and -25 =  -10.0\r\nThe copysign value of given list element gvn_lst[3] and 54 =  4.0<\/pre>\n

Program for copysign() Function in python<\/h2>\n