首页 > 文章列表 > python字典中values方法使用

python字典中values方法使用

python字典中values方法
342 2022-08-07

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

Python中的字典表示键(keys)和值(values)。

例如:

student_grades = {'John': 'A','Mary': 'C', 'Rob': 'B'}# To check grade of John, we call
print(student_grades['John'])

实例使用values方法:

dict = {'Sex': 'female', 'Age': 7, 'Name': 'Zara'}
print ("字典所有值为 : ",  list(dict.values()))

输出结果:

['female', 7, 'Zara']