如果您想提取字典中的某个键对应的值,可以使用字典的索引操作符 [] 来获取该键的值。

例如,如果您想获取 response_1.json()['data']['course'] 字典中的 'name' 键对应的值,可以使用以下代码:

course_name = response_1.json()['data']['course']['name']
print(course_name)

这将打印出 'name' 键对应的值。

根据您提供的数据示例,如果要提取其他键的值,只需将 'name' 替换为您想要提取的键的名称即可,例如:

preview_url = response_1.json()['data']['course']['preview_url']
description = response_1.json()['data']['course']['description']
introduction = response_1.json()['data']['course']['introduction']

这样,您就可以将 'preview_url''description''introduction' 分别设置为对应键的值。

请注意,提取键对应的值时,确保键的名称正确,并且字典中确实存在该键。否则,将会引发 KeyError 异常。

Python 字典提取特定键值:简单易懂的教程

原文地址: https://www.cveoy.top/t/topic/bplq 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录