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
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com