【发布时间】:2019-08-30 14:36:55
【问题描述】:
如何在 python3 复数中获取/打印虚部 J/j 的值?
我尝试使用下面的打印语句-
x=2345+4.567J
print(J)
print(x.J)
但在 python 3.7 中出现以下错误-
Traceback(最近一次调用最后一次): 文件“”,第 1 行,在 打印(J) NameError: 名称“J”未定义
Traceback(最近一次调用最后一次): 文件“”,第 1 行,在 打印(x.J) AttributeError:“复杂”对象没有属性“J”
>>> x=2345+4.567J
>>> print(J)
Traceback (most recent call last):
File "<pyshell#132>", line 1, in <module>
print(J)
NameError: name 'J' is not defined
>>> print(x.J)
Traceback (most recent call last):
File "<pyshell#134>", line 1, in <module>
print(x.J)
AttributeError: 'complex' object has no attribute 'J'
>>>
【问题讨论】:
标签: python-3.x