Python 字典项

Python 字典项函数返回可用字典项(总键和值)的列表。本节讨论此字典项函数的使用及其语法为:

dictionary_name.items()

字典项函数示例

items 函数返回给定字典中所有键值对的列表。下面的 items 代码打印 emp 和 employ 中的键值对。

提示:请参阅 Python 中的 字典

emp = {'name': 'Kevin', 'age': 25 , 'Sal': 725000}
print("Dictionary: ", emp)

# Print Items
print("Items: ", emp.items())

# Creating an Empty 
employ = {}
print("\nDictionary: ", employ)

# Print Values
print("Dictionary Items: ", employ.items())
Dictionary items function example