pop() method of dictionary

All dictionary methods

pop(), takes one argument ( key as input ) .

Returns : the value of the input key.

The original dictionary is changed after removal of key value pair.
my_dict={'a':'One','b':'Two','c':'Three'}
x=my_dict.pop('b')
print(x)
print(my_dict)
Output is here
Two
{'a': 'One', 'c': 'Three'}
If input key is not available then keyerror will be generated.
my_dict={'a':'One','b':'Two','c':'Three'}
x=my_dict.pop('d')
print(x)
print(my_dict)
Output ( error as input key is not available )
 KeyError: 'd'

All dictionary methods
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    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-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer