这是一段使用 Python 查询中国天气的代码示例:
import requests
def get_weather(city):
# 先定义一个函数, 用于查询天气
api_url = "http://api.openweathermap.org/data/2.5/weather"
# 定义 API 的地址
params = {
"q": city,
"appid": "your-api-key", # 替换为你的 API Key
"units": "metric",
}
# 定义请求参数
response = requests.get(ap