Apr 22, 2025
capitals = {} using curly braces."USA": "Washington DC"dir(dictionary_name) to see all attributes and methods.help(dictionary_name) for detailed descriptions.get method: dictionary_name.get(key).capitals.get("USA") returns "Washington DC".None.if statement.
if capitals.get("Japan"): print("Exists") else: print("Doesn't exist")update method to add or update key-value pairs.capitals.update({"Germany": "Berlin"}).capitals.update({"USA": "Detroit"}).pop to remove a specific key-value pair.
capitals.pop("China").popitem to remove the last inserted key-value pair.clear to remove all entries from the dictionary.keys method: dictionary_name.keys().values method: dictionary_name.values().items method: dictionary_name.items().get, update, pop, popitem, clear, keys, values, items.