Back
I just want to know, whether we can add a key to a python dictionary, once when it's created.
It doesn't appear to have an .add() function.
Try the following code:
d = {'key': 'value'}print(d)# {'key': 'value'}d['mynewkey'] = 'mynewvalue'print(d)# {'key': 'value', 'mynewkey': 'mynewvalue'}
d = {'key': 'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
# {'key': 'value', 'mynewkey': 'mynewvalue'}
Join the python online course fast, to learn python concepts in detail and get certified.
31k questions
32.8k answers
501 comments
693 users