items() function in dictionary of python by R4R Team

- items() is a python dictionary function which gets the all items in the dictionary and make a pair of each keys and their corresponding values.

Syntax-

dictionary.items()

Example

dictionary is {1:"one",2:"two"}
then items() return a pair like [(1:"one"),(2:"two")]


program-

d={1:None,2:None,3:None}
print("Enter value of key 1")
d[1]=input()
print("Enter value of key 2")
d[2]=input()
print("Enter value of key 3")
d[3]=input()

print(d.items())


output-

Enter value of key 1
one
Enter value of key 2
two
Enter value of key 3
three
dict_items([(1, 'one'), (2, 'two'), (3, 'three')])


-In this program, we have a dictionary {1:None,2:None,3:None} then by input we set the values of the keys then print the dictionary with d.items().




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!