Python Dictionary Items method Definition and usage

Python Dictionary Items Method

Python dictionary 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 the example below.

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

Syntax:

dictionary.items()

Example:

x = ([('name', 'pramod'), ('age', 22), ('rollno', '17691a05b9'), ('class', 'B-Tech')])
x = dict(x) # convering into dictionary
y = x.items()
x['age'] = 22
print(y,'\n') # break the line

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

OutPut

Python Dictionary Items Method

Recommended Post:

 

Python Dictionary Items method Definition and usage

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment