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