Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


The dictionary items() method is used to display all key-value pair present in the dictionary. It displays key-value in a list with each pair in a tuple. If the dictionary is modified, the display object also gets updated. Please see example for more details.

Syntax

dictionary.items()

Parameters

No parameter is required.

Return Value

Returns dict_items containing all key-value pair present in the dictionary.

Example:

In the below example, the items() method to used to display all key-value pairs in the given dictionary.

Info = {
   'name': 'John',
   'age': 25
}
#display a list of tuple containing all key-value pairs.
x =  Info.items() 
print(x)

#Adding a new field, display object also gets changed. 
Info['city'] = 'London'
print(x)

The output of the above code will be:

dict_items([('name', 'John'), ('age', 25)])

dict_items([('name', 'John'), ('age', 25), ('city', 'London')])

❮ Python Dictionary Methods