python cmath_Python复数– cmath

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 =
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值