Dictionary
Dictionary
Methods
Ali Moustafa
@ali-moustafa2000
clear()
The "clear()" method removes all items from
the dictionary.
@ali-moustafa2000
copy()
The "copy()" method returns a shallow copy of the
dictionary.
NB: changes to the copy of the dictionary do not
affect the original dictionary.
@ali-moustafa2000
get()
The "get()" method returns the value of the
specified key. If the key is not present in the
dictionary, it will return "None" or a default value
specified as the second argument of the method.
@ali-moustafa2000
items()
The "items()" method returns a list of key-value
pairs in the dictionary.
@ali-moustafa2000
keys()
The "keys()" method returns a list of keys in the
dictionary.
@ali-moustafa2000
values()
The "values()" method Returns a list of values in
the dictionary.
@ali-moustafa2000
pop()
The "pop()" method removes and returns the
value of the specified key. If the key does not
exist, it raises a KeyError.
To avoid this, you can pass a default value to
be returned if the key is not found.
@ali-moustafa2000
popitem()
The "popitem()" method removes and returns
the last inserted key-value pair in the dictionary.
If the dictionary is empty, it raises a KeyError.
@ali-moustafa2000
setdefault()
The "setdefault()" method returns the value of the
specified key.
If the key does not exist, it inserts the key with the
specified default value.
@ali-moustafa2000
update()
@ali-moustafa2000