Dictionary Methods
Dictionary Methods
------------------
dict.clear()
Purpose: To remove all items form dictionary
Parameters taken: Not taking any parameter
Return: NoneType
dict.copy()
Purpose: To make a copy of dictionary
parameter taken: not taking any parameter
Return: dict
dict.fromkeys(keys, value=None)
Purpose: To create a dictionary with the specified keys and the specified value
dict.get(keyname, value)
Purpose:To get the value of the item with the specified key
Parameter taken:1.keyname required the keyname of the item you want to return
the value from
2.value optional a value to return if the specified key does
not exits default value is None
Return: which value having that data type will return.
dict.items()
Purpose: to view object contains the key-value pairs of the dictionary as
tuples in a list.
Parameters taken: no parameters taken
Reture: dict item list
dict.keys()
Purpose : To view the object contais the keys of the dictionary as a list
parameters taken: no parameter taken
Return: dict keys list
dict.pop(keyname, value)
Purpose:to removes the specified items form the dictionary
if the parameter is not specified and the no item with the specified
key is found
an error is raised
Parameter taken: 1.keyname required the keyname of the item you want to remove
2.value optional a value to return if the specified key do not
exits
Retuen : it will return removed value (str)
dict.popitem()
Purpose: to removes last inserted item into the dictinary
Parameter taken : no parameter taken
Return : removed key,value (tuple )
dict.setdefault(keyname, value)
Purpose: To set the value of the item with the specified key
Parameters taken: 1.keyname required the key name of the item you want to
return the value from
2. value optional if the key exist then parameter has no
effect, if the key does
not exist, the value becomes the keys default value None
Return: provided type of value
dict.update(iterable)
Purpose: To insert the specified items to the dictionary
Parameters taken: 1. iterable a dictionary of iterable object with key value
pairs that will be
inserted to the dictionary
Return: Nonetype
dict.values()
Purpose: To view teh object contains the values of teh dictionary as a list
parameter taken: not taking any parameter
Return: dict value