Add / update
person["email"] = "alice@example.com"
person["age"] = 29
person.update({"age": 30, "city": "Rolla"})
Delete
del person["city"]
email = person.pop("email")
phone = person.pop("phone", "N/A")
last = person.popitem()
del also removes list elements, slices, and variable bindings. It does not return a value.
Dictionary pop(key, default) uses a key and an optional fallback. List pop(index) uses an optional index and has no fallback. Without a fallback, a missing dictionary key raises KeyError. Like list pop(), d.popitem() removes the last item, but returns a (key, value) tuple.
Useful inspection methods
person.keys()
person.values()
person.items()
len(person)
dict.keys(), .values(), and .items() return view objects — they reflect changes to the dict in real time.