keys() method of dictionary

All dictionary methods

keys(), takes no argument ( inputs ) .

Returns : the view object as a list of keys of dictionary.

The original dictionary remain same without any change.
my_dict={'a':'One','b':'Two','c':'Three'}
k=my_dict.keys()
print(k)
Output is here
dict_keys(['a', 'b', 'c'])

View object

The view object created by keys() method will reflect the changes in dictionary.
my_dict={'a':'One','b':'Two','c':'Three'}
k=my_dict.keys()
print(k)
my_dict['d']='Four' # one key value pair added
print(k)   # changes are reflected. 
Output
dict_keys(['a', 'b', 'c'])
dict_keys(['a', 'b', 'c', '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