Python 字典 update() 方法
實例
向字典插入項目:
car = { "brand": "Porsche", "model": "911", "year": 1963 } car.update({"color": "White"}) print(car)
定義和用法
update() 方法向字典插入指定的項目。
這個指定項目可以是字典或可迭代對象。
語法
dictionary.update(iterable)
參數值
參數 | 描述 |
---|---|
iterable | 具有鍵值對的字典或可迭代對象,會被插入到字典中。 |