Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 568 Bytes

26.md

File metadata and controls

32 lines (24 loc) · 568 Bytes
rank vote view answer url
26 2686 3539652 16 url

字典里添加元素的方法

当一个字典被创建了,能不能在字典里计入一个键?好像没有.add()的方法.


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

>>> x = {1:2}
>>> print x
{1: 2}

>>> x.update({3:4})
>>> print x
{1: 2, 3: 4}