如何将for循环中的值连接到空字符串
我正在尝试在IP数据字典中找到“ LAT”和“ LON”键,然后将这些键的值添加到空的“ LAT”和“ LON”变量中。然后将它们添加到Google变量中,以获取Google Maps链接工作。请帮忙。
导入请求
r = requests.get(f"http://ip-api.com/json/50.40.70.18?fields=24895487")
data = r.json()
print(data)
lat = ""
lon = ""
google = f"https://maps.google.com?q={lat},{lon}"
for key, value in data.items():
if key == 'lat':
lat += str(value)
if key == 'lon':
lon += str(value)
print(google)
I am trying to find "lat" and "lon" keys in IP data dictionary and then add the values of those keys to empty "lat" and "lon" variables. Then add them in google variable, to get working google maps link. Please help.
import requests
r = requests.get(f"http://ip-api.com/json/50.40.70.18?fields=24895487")
data = r.json()
print(data)
lat = ""
lon = ""
google = f"https://maps.google.com?q={lat},{lon}"
for key, value in data.items():
if key == 'lat':
lat += str(value)
if key == 'lon':
lon += str(value)
print(google)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)