Back
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.
To add a new keys to a dictionary you can use the below-mentioned code:-
d = {'key':'value'} print(d) d['mynewkey'] = 'mynewvalue' print(d)
d = {'key':'value'}
print(d)
d['mynewkey'] = 'mynewvalue'
To know more about this you can have a look at the following video tutorial:-
31k questions
32.8k answers
501 comments
693 users