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

Hi, I’m Pramod Kumar Yadav & a computer science Engineer with 3years of experience in Digital marketing. I’m self-motivated and love to do SEO.




Best PYthon Course

Get More trending Courses

Leave a Reply

%d bloggers like this: