Easy Tutorial
❮ Python Mongodb Delete Document Python Os Fsync ❯

Python3 Dictionary items() Method

Python3 Dictionary


Description

The Python dictionary items() method returns a view object that displays a list of a dictionary's key-value tuple pairs.

dict.keys(), dict.values(), and dict.items() all return view objects, which provide a dynamic view of the dictionary entries. This means that any changes in the dictionary are reflected in the view.

View objects are not lists and do not support indexing. They can be converted to lists using the list() function.

We cannot modify the view objects directly, as they are read-only.

Syntax

Syntax for the items() method:

dict.items()

Parameters

Return Value

Returns a view object.

Example

The following example demonstrates the use of the items() method:

#!/usr/bin/python3

tinydict = {'Name': 'tutorialpro', 'Age': 7}

print("Value : %s" % tinydict.items())

The output of the above example is:

Value : dict_items([('Age', 7), ('Name', 'tutorialpro')])

Python3 Dictionary

❮ Python Mongodb Delete Document Python Os Fsync ❯