gpt4 book ai didi

python - 值错误 : could not convert string tofloat. 为什么? (Python)

转载 作者:太空宇宙 更新时间:2023-11-03 20:47:44 25 4
gpt4 key购买 nike

how to convert str in float?

paris=requests.get('https://www.metaweather.com/api/location/search/?query=paris').json()
paris_latlong=paris[0]['latt_long']
a=float(paris_latlong)
print(a)

ValueError: could not convert string tofloat.

最佳答案

试试这个:

paris=requests.get('https://www.metaweather.com/api/location/search/?query=paris').json()
paris_latlong=paris[0]['latt_long'].split(',')
a=float(paris_latlong[0])
b=float(paris_latlong[1])
print(a, b)

关于python - 值错误 : could not convert string tofloat. 为什么? (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56463191/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com