Python Dictionary Methods

MethodDescription
clear()Removes all items from the dictionary.
copy()Returns a shallow copy of the dictionary.
fromkeys(keys, value)Creates a new dictionary with keys from the iterable and values set to a specified value.
get(key, default)Returns the value for a given key if it exists; otherwise, returns a default value.
items()Returns a view of all key-value pairs in the dictionary.
keys()Returns a view of all keys in the dictionary.
pop(key, default)Removes and returns the value for a given key; if key is not found, returns the default value.
popitem()Removes and returns an arbitrary key-value pair from the dictionary.
setdefault(key, default)Returns the value for a given key if it exists; otherwise, sets a default value and returns it.
update(iterable)Updates the dictionary with key-value pairs from an iterable.
values()Returns a view of all values in the dictionary.