What is items() method in dictionary | How to use the items() method of the dictionary.


This method returns a view object, a view object contains a list of tuples.

 [ ( ) , ( ) , ( ) , ( ) ] and these tuples contain key value pairs. Also this view object is directly connected to the original dictionary, meaning any changes in the original dictionary will be reflected directly into view object.


X = dictionary.items()

This method takes no argument.




You can copy code here.

dictionary = {1: ‘Student’,
‘Name’: ‘Waqar Khan’,
‘Age’: 23,
‘Male’: True,
‘Subject’: ‘Computers’}
x = dictionary.items()
dictionary[‘Subject’] = ‘Physics’


  1. A dictionary with some values is being taken
  2. items() method is being applied to the dictionary and that result is passed in the ‘x’ variable which becomes a view object for the dictionary.
  3. Now, dictionary is updated with its subject’s value to Computers.
  4. No changes are explicitly made inside ‘x’ which is a view object, but since it is a view object, it will reflect changes.


  1. A list of tuples with key value pairs is printed.
  2. An updated view object is printed.

Related Post.

Waqar Khan

Hello, everyone, I am Waqar Khan. I have done my B.tech in Computer Science. I love to write about Computer Informational blogs. Before write I did proper research on it. Hope you like our blogs. Thank you.

Related Posts

Leave a Reply

Your email address will not be published.