如何在浮点数中转换str?
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:无法将字符串转换为浮点数。
答案 0 :(得分:0)
尝试一下:
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)