📜  Python|十进制 conjugate() 方法

📅  最后修改于: 2022-05-13 01:55:00.040000             🧑  作者: Mango

Python|十进制 conjugate() 方法

Decimal#conjugate() : conjugate()是一个返回自身的 Decimal 类方法,该方法仅符合 Decimal 规范

Syntax: 
Decimal.conjugate()

Parameter: 
Decimal values

Return: 
the self Decimal value

代码 #1:conjugate() 方法的示例

# Python Program explaining 
# conjugate() 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.conjugate() method
print ("\n\nDecimal a with conjugate() method : ", a.conjugate())
  
print ("Decimal b with conjugate() method : ", b.conjugate())

输出 :

Decimal value a :  -1
Decimal value b :  0.142857


Decimal a with conjugate() method :  -1
Decimal b with conjugate() method :  0.142857

代码 #2:conjugate() 方法的示例

# Python Program explaining 
# conjugate() 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.conjugate() method
print ("\n\nDecimal a with conjugate() method : ", a.conjugate())
  
print ("Decimal b with conjugate() method : ", b.conjugate())

输出 :

Decimal value a :  -3.14
Decimal value b :  3.21E+7


Decimal a with conjugate() method :  -3.14
Decimal b with conjugate() method :  3.21E+7