Is it possible to add a key to a Python dictionary after it has been created?
It doesn\'t seem to have an .add() method.
.add()
To add multiple keys simultaneously, use dict.update():
>>> x = {1:2} >>> print(x) {1: 2} >>> d = {3:4, 5:6, 7:8} >>> x.update(d) >>> print(x) {1: 2, 3: 4, 5: 6, 7: 8}
For adding a single key, the accepted answer has less computational overhead.