ValueError: complex() arg is a malformed string解决办法
在Python使用complex()
函数对字符串进行转换时,字符串在+
或-
的周围必须不能有空格。例如complex('1+2j')
是合法的,但complex('1 + 2j')
会触发ValueError
异常。
complex("1+2j") #合法
complex("1 + 1j") #非法
在上面的例子中,第二行会造成ValueError
类型错误:ValueError: complex() arg is a malformed string