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 j
or . 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:
- c1 = 12 + 0.2j
- print("c1Value: ", c1)
- print("c1Type", type(c1))
- c2 = 6 - 1.2j
- print("c2Value: ", c2)
- # Perform simple calculations on complex numbers
- print("c1+c2: ", c1+c2)
- 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.