python dict values()
时间: 2023-11-23 17:55:22 浏览: 140
在Python中,dict对象有一个values()方法,该方法可以将字典转换为包含所有value的列表。这意味着我们可以迭代字典的每个value。例如,如果我们有以下字典:
d = {'Adam': 95, 'Lisa': 85, 'Bart': 59}
我们可以使用d.values()方法来获取所有的value,如下所示:
values = d.values()
print(values) # [85, 95, 59]
然后,我们可以使用for循环迭代values,打印每一个value:
for v in values:
print(v)
# 85
# 95
# 59
这样,我们就可以逐个访问字典中的每个value了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Python 迭代dict的value](https://blog.csdn.net/weixin_34220179/article/details/85664986)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [Python 字典中的values函数](https://blog.csdn.net/m0_48978908/article/details/119333584)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文