Pythonディクショナリupdate()メソッド
例
辞書に項目を挿入します。
car = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
car.update({"color": "White"})
print(car)
定義と使用法
このupdate()
メソッドは、指定された項目を辞書に挿入します。
指定する項目は、ディクショナリ、またはキーと値のペアを持つ反復可能なオブジェクトです。
構文
dictionary.update(iterable)
パラメータ値
Parameter | Description |
---|---|
iterable | A dictionary or an iterable object with key value pairs, that will be inserted to the dictionary |