#I have a string array as,
ele =["o","al","ag",'fe']
#And defined a float variable as,
eqoo = float(2.540761)
stre1 = ele[0]
stre2 = ele[0]
eqdist = ("eq"+str(stre1)+str(stre2))
print float(eqdist)
위의 인쇄 문은 나에게 오류를 제공합니다.
Traceback (most recent call last):
File "plotdistorg.py", line 64, in <module>
print float(eqdist)
ValueError: could not convert string to float: eqoo
내가 여기서 뭘 잘못하고 있니?
변수 eqoo
값 을 얻고 싶다고 생각합니다 . 변수 이름 eqoo
과 문자열 값 "eqoo"
은 다릅니다.
변수 eqoo
값 을 얻으려면 :
>>> globals()[eqdist]
2.540761
그리고 그것을 float로 변환하고 싶다면 (이 경우 이미 있습니다!)
>>> print float(globals()[eqdist])
2.540761
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다