Add key to a dictionary in Python

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

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.

Answers

>>> d = { key : value }
>>> print d
{ key :  value }
>>> d[ mynewkey ] =  mynewvalue 
>>> print d
{ mynewkey :  mynewvalue ,  key :  value }

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/1024847/add-key-to-a-dictionary-in-python

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils