my_dict={'a':'One','b':'Two','c':'Three'}
k=my_dict.keys()
print(k)
Output is here
dict_keys(['a', 'b', 'c'])
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'])
my_dict = {'a': 'One', 'b': 'Two', 'c': 'Three'}
for key in my_dict.keys():
print(key)
Use Case: Checking If a Key Exists:if 'b' in my_dict.keys():
print("Key 'b' is present")
Difference Between keys() and Direct Access:Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.