python cmath
A complex number is created from two real numbers. Python complex number can be created using complex() function as well as using direct assignment statement.
从两个实数创建一个复数。 可以使用complex()函数以及直接赋值语句创建Python复数。
Complex numbers are mostly used where we define something using two real numbers. For example, a circuit element that is defined by Voltage (V) and Current (I). They are mostly used in geometry, calculus and scientific calculations.
复数通常用在我们使用两个实数定义事物的地方。 例如,由电压(V)和电流(I)定义的电路元件。 它们主要用于几何,微积分和科学计算。
Python复数 (Python Complex Numbers)
Let’s first learn how to create complex numbers in python.
让我们首先学习如何在python中创建复数。
c = 1 + 2j
print(type(c))
print(c)
c1 = complex(2, 4)
print(type(c1))
print(c1)
Output:
输出:
<class 'complex'>
(1+2j)
<class 'complex'>
(2+4j)
Python complex numbers are of type complex
. Every complex number contains one real part and one imaginary part.
Python复数的类型为complex
。 每个复数包含一个实部和一个虚部。
Python复数的属性和函数 (Python Complex Numbers Attributes and Functions)
Let’s look at some attributes and instance functions of complex numbers.
让我们看一下复数的一些属性和实例函数。
c = 1 + 2j
print('Real Part =', c.real)
print('Imaginary Part =', c.imag)
print('Complex conjugate =', c.conjugate())
Output:
输出:
Real Part = 1.0
Imaginary Part = 2.0
Complex conjugate =