Python Dictionary Methods
keys() → Returns all keys in the dictionary.
values() → Returns all values in the dictionary.
items() → Returns key-value pairs as tuples.
get(key, default) → Returns the value of the key; returns default if key not found.
update(other_dict) → Updates dictionary with another dictionary (or key-value pairs).
pop(key, default) → Removes the specified key and returns its value.
popitem() → Removes and returns the last inserted key-value pair.
clear() → Removes all items from the dictionary.
copy() → Returns a shallow copy of the dictionary.
setdefault(key, default) → Returns value of the key; if key doesn’t exist, inserts it with default.
fromkeys(keys, value) → Creates a new dictionary from given keys with the same value.
Example:
my_dict = {'a': 1, 'b': 2, 'c': 3}
print(my_dict.keys()) # dict_keys(['a', 'b', 'c'])
print(my_dict.values()) # dict_values([1, 2, 3])
print(my_dict.items()) # dict_items([('a', 1), ('b', 2), ('c', 3)])
print(my_dict.get('b')) # 2
my_dict.update({'d': 4})
print(my_dict) # {'a': 1, 'b': 2, 'c': 3, 'd': 4}