Python3 Dictionary items() Method
Description
The Python dictionary items() method returns a view object as a list, which is a traversable key/value pair.
dict.keys()、dict.values()Like dict.items(), it returns a view object, providing a dynamic view of the dictionary entity. This means that when the dictionary changes, the view changes accordingly.
A view object is not a list and does not support indexing. You can use list() to convert it to a list.
We cannot make any modifications to a view object, because dictionary view objects are read-only.
Syntax
Syntax of the items() method:
dict.items()
Parameters
- NA。
Return Value
Returns a view object.
Example
The following example demonstrates the usage of the items() method:
Example
#!/usr/bin/python3
tinydict = {'Name': 'Example', 'Age': 7}
print ("Value : %s" % tinydict.items())
The output of the above example is:
Value : dict_items([('Age', 7), ('Name', 'Example')])
Other Extensions
Python3 Dictionary