items() method of dictionary

All dictionary methods

items(), takes no argument ( inputs ) .

Returns : the list view object with tuple of key value pairs using all elements of dictionary.

The original dictionary remain same without any change.
my_dict={'a':'One','b':'Two','c':'Three'}
x=my_dict.items()
print(x)
print(type(x))
Output is here
dict_items([('a', 'One'), ('b', 'Two'), ('c', 'Three')])
<class 'dict_items'>

View object

The view object created by items() method will reflect the changes in dictionary.
my_dict={'a':'One','b':'Two','c':'Three'}
x=my_dict.items()
print(x)
del(my_dict['b']) # deleted one item with key b
print(x)
Output
dict_items([('a', 'One'), ('b', 'Two'), ('c', 'Three')])
dict_items([('a', 'One'), ('c', 'Three')])

All dictionary methods


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer