解决ValueError: complex() arg is a malformed string

ValueError: complex() arg is a malformed string

原因:

使用complex()方法将字符串转化为复数的时候,字符串中有空格符。

# 错误代码:
print(complex('1 + 2j'))  # complex中的字符串‘+’号两边不能有空格
# 修改后:
print(complex('1+2j'))  # 正确
发布了15 篇原创文章 · 获赞 4 · 访问量 820

猜你喜欢

转载自blog.csdn.net/qq_41320433/article/details/104377397