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

Dictionary Data Type Method in Python

A Dictionary in Python is a collection of data stored in key-value pairs. Key methods include update(), pop(), get(), keys(), values(), and items(), which allow for various operations such as adding, removing, and retrieving data. Additional methods like copy(), clear(), and fromkeys() provide further manipulation capabilities.

Uploaded by

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

Dictionary Data Type Method in Python

A Dictionary in Python is a collection of data stored in key-value pairs. Key methods include update(), pop(), get(), keys(), values(), and items(), which allow for various operations such as adding, removing, and retrieving data. Additional methods like copy(), clear(), and fromkeys() provide further manipulation capabilities.

Uploaded by

Manasa P
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Dictionary data type method in python

Dictionary Data Type

A Dictionary is a collection of data stored in key-value pairs enclosed within curly braces {}

Dictionary Methods

• update() – Adds new key-value pairs or updates existing values.


• pop() – Removes the specified key and returns its value.
• popitem() – Removes and returns the last inserted key-value pair.
• get() – Returns the value of the specified key.
• keys() – Returns all keys in the dictionary.
• values() – Returns all values in the dictionary.
• items() – Returns all key-value pairs as tuples.
• copy() – Creates a copy of the dictionary.
• clear() – Removes all items from the dictionary.
• setdefault() – Returns the value of a key; if absent, inserts the key with a default value.
• fromkeys() – Creates a new dictionary with specified keys and a common value.
• len() – Returns the number of key-value pairs in the dictionary.
• in – Checks whether a key exists in the dictionary.
• del – Deletes a specified key or the entire dictionary.
• dict() – Creates a new dictionary.
• sorted() – Returns the dictionary keys in sorted order.
• update() – Merges another dictionary into the current dictionary.
• values() – Retrieves all values stored in the dictionary.
• keys() – Retrieves all keys stored in the dictionary.
• items() – Retrieves all key-value pairs stored in the dictionary.
Output

You might also like