Python字典items()方法与示例
词典items()方法
items()方法用于获取所有项作为视图对象,该视图对象表示字典的键值对。
语法:
dictionary_name.items()
Parameter(s):
它不接受任何参数。
返回值:
此方法的返回类型为<class'dict_items'>,它将字典的项作为视图对象返回。
示例
#Python字典items()方法与示例
#字典声明
student = {
"roll_no": 101,
"name": "Shivang",
"course": "B.Tech",
"perc" : 98.5
}
#印刷词典
print("data of student dictionary...")
print(student)
#印刷品
print("items of student dictionary...")
print(student.items())
#学生的打印返回类型.items()方法
print("return type is: ", type(student.items()))输出结果
data of student dictionary...
{'name': 'Shivang', 'perc': 98.5, 'roll_no': 101, 'course': 'B.Tech'}
items of student dictionary...
dict_items([('name', 'Shivang'), ('perc', 98.5), ('roll_no', 101), ('course', 'B.Tech')])
return type is: <class 'dict_items'>热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话