Linux 拨号vps windows公众号手机端

python复数的虚部如何表示

lewis 7年前 (2018-01-20) 阅读数 7 #程序编程
文章标签 python

Python中的复数虚部可以通过使用后缀`j`或`J`来表示。

以下是一些示例:

```python
a = 3 + 2j
b = 1j
c = 1 + 0j

print(a.imag) # 输出:2.0
print(b.imag) # 输出:1.0
print(c.imag) # 输出:0.0
```

在上述示例中,变量`a`表示复数3+2j,其中虚部为2。变量`b`表示纯虚数1j,其中虚部为1。变量`c`表示实数1,虚部为0。

你还可以使用`complex()`函数来创建复数,例如:

```python
d = complex(2, -5) # 创建复数2-5j

print(d.imag) # 输出:-5.0
```

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门