如何在python中将字符串转换为复数?
How to convert string into complex number in python?
我想使用 python 创建一个特殊的计算器,但为此我应该了解更多有关复数的知识。我的计算器必须得到一个字符串并输出复杂的方程式。请帮助我。
myinput = "5 + 2j"
myoutput = ConvertToComplex(myinput) * (3 + 12j) #please help me with writing this function
print(myoutput)
您要查找的功能已内置于 python 中。你只需要先去掉空格:
myinput = "5 + 2j"
mycleaninput = myinput.replace(" ","")
myoutput = complex(mycleaninput) * (3 + 12j)
print(myoutput)
我想使用 python 创建一个特殊的计算器,但为此我应该了解更多有关复数的知识。我的计算器必须得到一个字符串并输出复杂的方程式。请帮助我。
myinput = "5 + 2j"
myoutput = ConvertToComplex(myinput) * (3 + 12j) #please help me with writing this function
print(myoutput)
您要查找的功能已内置于 python 中。你只需要先去掉空格:
myinput = "5 + 2j"
mycleaninput = myinput.replace(" ","")
myoutput = complex(mycleaninput) * (3 + 12j)
print(myoutput)