Detailed explanation of Python complex types (complex)

0c21cdcd12084449ab54677daa249b91.png

 

Complex is  a built-in type of Python  and can be written directly. In other words, the Python language itself supports plurals without relying on the standard library or third-party libraries.

A complex number consists of a real part (real) and an imaginary part (imag). In Python, the imaginary part of a complex number is suffixed with jor . The specific format is:J

a + bj

a represents the real part and b represents the imaginary part.

[Example] Use of plural numbers in Python:

 
  1. c1 = 12 + 0.2j
  2. print("c1Value: ", c1)
  3. print("c1Type", type(c1))
  4.  
  5. c2 = 6 - 1.2j
  6. print("c2Value: ", c2)
  7.  
  8. # Perform simple calculations on complex numbers
  9. print("c1+c2: ", c1+c2)
  10. print("c1*c2: ", c1*c2)

operation result:

c1Value:  (12+0.2j)
c1Type <class 'complex'>
c2Value:  (6-1.2j)
c1+c2:  (18-1j)
c1*c2:  (72.24-13.2j)

It can be found that the internal type of complex numbers in Python is complex, and Python supports simple calculations of complex numbers by default.

 

Supongo que te gusta

Origin blog.csdn.net/weixin_74774974/article/details/133420791
Recomendado
Clasificación