Python Dictionary | Items method | Definition and usage

Python Dictionary | Items method | Definition and usage
Items method

Definition and usage

The item () method returns a visible object. The
 visual object contains the dictionary's key-value
 pairs, such as tuples in a list.

The visual object will reflect any changes made to
 the dictionary, see example below.


dictionary.items ()
Parameter value
No parameters

Python item() method returns a new view of the dictionary. This view is collection of key value tuples. This method does not take any parameter and returns empty view if the dictionary is empty.

user_items = user_info.items()


 dict_items([('name', 'pramod'), ('age', 22)
, ('rollno', '17691a05b9'), ('class', 'B-Tech')])
#this is printing like tuple item inside a list

for key,value in user_info.items():
    print(f'key is {key} and values is {value}')


key is name and values is pramod
key is age and values is 22key is rollno and 
                    values is 17691a05b9
key is class and values is B-Tech

Leave a Comment

Your email address will not be published. Required fields are marked *