Square brackets read an existing key or assign a value to a key. Assignment adds a missing key and replaces the value of an existing one.
stock = {}
stock["pens"] = 3
stock["paper"] = 8
stock["pens"] = stock["pens"] + 2
print(stock)
print(stock.get("clips", 0))
{'pens': 5, 'paper': 8}
0
Reading stock["clips"] would raise KeyError because the key is absent. get returns its supplied default instead, without inserting the key. Without an explicit default it returns None; if None is also a legitimate stored value, use "clips" in stock to distinguish presence from absence.
stock = {"pens": 5, "paper": 8}
removed = stock.pop("pens")
del stock["paper"]
print(removed)
print(stock)
5
{}
pop removes a key and returns its value; del removes the entry without returning the value. Both raise KeyError for an absent key unless pop is given a default. Changing a dictionary through an alias changes the same object; stock.copy() makes a shallow copy.