0% found this document useful (0 votes)
7 views2 pages

Dictionary Methods

The document outlines various methods available for Python dictionaries, including their purposes, parameters, and return types. Key methods include dict.clear(), dict.copy(), dict.fromkeys(), dict.get(), dict.items(), dict.keys(), dict.pop(), dict.popitem(), dict.setdefault(), dict.update(), and dict.values(). Each method serves specific functions for manipulating dictionary data structures.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

Dictionary Methods

The document outlines various methods available for Python dictionaries, including their purposes, parameters, and return types. Key methods include dict.clear(), dict.copy(), dict.fromkeys(), dict.get(), dict.items(), dict.keys(), dict.pop(), dict.popitem(), dict.setdefault(), dict.update(), and dict.values(). Each method serves specific functions for manipulating dictionary data structures.

Uploaded by

bhushan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

Parameters taken:1.keys required an iterable specifing the keys of the new


dictionary
2.value optional the value for all keys default value is None
Return : dict

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

You might also like