Python | Decimal copy_sign() method Last Updated : 11 Oct, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report Decimal#copy_sign() : copy_sign() is a Decimal class method which returns the copy of the first Decimal value with the sign set to be the same as the sign of the second Decimal value. Syntax: Decimal.copy_sign() Parameter: Decimal values Return: the copy of the first Decimal value with the sign set to be the same as the sign of the second Decimal value. Code #1 : Example for copy_sign() method Python3 # Python Program explaining # copy_sign() method # loading decimal library from decimal import * # Initializing a decimal value a = Decimal(-1) b = Decimal('0.142857') # printing Decimal values print ("Decimal value a : ", a) print ("Decimal value b : ", b) # Using Decimal.copy_sign() method print ("\n\nDecimal a with copy_sign() method : ", a.copy_sign(a)) print ("Decimal a with copy_sign() method : ", a.copy_sign(b)) print ("Decimal b with copy_sign() method : ", b.copy_sign(a)) Output : Decimal value a : -1 Decimal value b : 0.142857 Decimal a with copy_sign() method : -1 Decimal a with copy_sign() method : 1 Decimal b with copy_sign() method : -0.142857 Code #2 : Example for copy_sign() method Python3 # Python Program explaining # copy_sign() method # loading decimal library from decimal import * # Initializing a decimal value a = Decimal('-3.14') b = Decimal('321e + 5') # printing Decimal values print ("Decimal value a : ", a) print ("Decimal value b : ", b) # Using Decimal.copy_sign() method print ("\n\nDecimal a with copy_sign() method : ", a.copy_sign(a)) print ("Decimal a with copy_sign() method : ", a.copy_sign(b)) print ("Decimal b with copy_sign() method : ", b.copy_sign(a)) Output : Decimal value a : -3.14 Decimal value b : 3.21E+7 Decimal a with copy_sign() method : -3.14 Decimal a with copy_sign() method : 3.14 Decimal b with copy_sign() method : -3.21E+7 Comment More infoAdvertise with us Next Article Python | Decimal copy_sign() method N noobestars101 Follow Improve Article Tags : Python Practice Tags : python Similar Reads Python | Decimal compare_signal() method Decimal#compare_signal() : compare_signal() is a Decimal class method which compares th two Decimal values, except for the NaN values. Syntax: Decimal.compare_signal()Parameter: Decimal valuesReturn: 1 - if a > b -1 - if a < b 0 - if a = b Code #1 : Example for compare_signal() method Python 2 min read Python | Decimal copy_abs() method Decimal#copy_abs() : copy_abs() is a Decimal class method which returns the absolute Decimal value. Syntax: Decimal.copy_abs() Parameter: Decimal values Return: the absolute Decimal value Code #1 : Example for copy_abs() method Python3 # Python Program explaining # copy_abs() method # loading decima 2 min read Python | Decimal is_signed() method Decimal#is_signed() : is_signed() is a Decimal class method which checks whether the sign of Decimal value is negative Syntax: Decimal.is_signed() Parameter: Decimal values Return: true - if the sign of Decimal value is negative; otherwise false Code #1 : Example for is_signed() method Python3 # Pyt 2 min read Python | Decimal shift() method Decimal#shift() : shift() is a Decimal class method which returns the shifted copy of x, y times Syntax: Decimal.shift() Parameter: Decimal values Return: the shifted copy of x, y times Code #1 : Example for shift() method Python3 # Python Program explaining # shift() method # loading decimal librar 2 min read Python | Decimal compare() method Decimal#compare() : compare() is a Decimal class method which compares the two Decimal values. Syntax: Decimal.compare() Parameter: Decimal values Return: 1 - if a > b -1 - if a < b 0 - if a = b Code #1 : Example for compare() method Python3 # Python Program explaining # compare() method # loa 2 min read Like