my_dict = {'a': 'One', 'b': 'Two', 'c': 'Three'}
for key in my_dict.keys():
print(key)
Use Case: Checking If a Key Exists:
Example of checking if a key exists in a dictionary using keys().
if 'b' in my_dict.keys():
print("Key 'b' is present")
Difference Between keys() and Direct Access: keys() returns a view object while direct access (my_dict['key']) looks up a specific key-value pair.
« All dictionary methods