Home >>Python Dictionary Methods >Python Dictionary items() Method

Python Dictionary items() Method

Python Dictionary items() Method

Python Dictionary items() Method in python dictionary returns a new view object of the dictionary (key, value) as tuple pairs in a list. It does not take any parameter.

Syntax:
dictionary.items()
Here is an example of Python Dictionary items() Method:

det = 
{
"name": "ram",
"lastname": "Mustang",
"year": 1990
}
a = det.items()
print(a)

Output:
dict_items([('name', 'ram'), ('lastname', 'Mustang'), ('year', 1990)])
Example 2:

per = {'name':'sohan', 'course':'m.Tech', 'email':'sohan@gmail.com'}   
for st in per:  
print("(",st, ":", per[st], end="), ")       
items = per.items()   
print("\n", items)

Output:
( name : sohan), ( course : m.Tech), ( email : sohan@gmail.com), dict_items([('name', 'sohan'), ('course', 'm.Tech'), ('email', 'sohan@gmail.com')])

No Sidebar ads