popitem() method of dictionary

All dictionary methods

popitem(), takes no argument ( inputs ) .

Returns : the key value pair of recently added to dictionary as a tuple.

The original dictionary is changed after removal of key value pair.
my_dict={'a':'One','b':'Two','c':'Three'}
x=my_dict.popitem()
print(x)
print(my_dict)
Output is here
('c', 'Three')
{'a': 'One', 'b': 'Two'}
popitem() will remove the latest added element
my_dict={'a':'One','b':'Two','c':'Three'}
my_dict['d']='Four'
x=my_dict.popitem()
print(x)
print(my_dict)
Output
('d', 'Four')
{'a': 'One', 'b': 'Two', 'c': 'Three'}
Data type of removed item is tuple
my_dict={'a':'One','b':'Two','c':'Three'}
x=my_dict.popitem()
print(type(x))
Output
<class 'tuple'>

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