Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the update () method of Python dictionary

Shulou Source: shulou.com Published: 2022-06-01 21:00:41 10月03日 Update

This article mainly explains how to use the update () method of the Python dictionary. The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to use the update () method of the Python dictionary.

Update ([other]) updates the dictionary with the key / value pair from other, overwriting the original key. Return to None. Update () accepts another dictionary object, or an iterable object that contains key / value pairs represented by tuples of length two or other iterable objects. If a keyword argument is given, the dictionary is updated with its specified key / value pair: d.update (red=1, blue=2).

The code lab demonstrates:

Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license ()" for more information. > > D1 = {"Zhejiang": "Hangzhou", "Jiangsu": "nanjing"} > > D1 {'Zhejiang': 'Hangzhou' 'Jiangsu': 'nanjing'} > d1.update (Jiangsu = "Nanjing") > D1 {' Zhejiang': 'Hangzhou', 'Jiangsu': 'Nanjing'} > D2 = {"Shandong": "Jinan", "Hebei": "Shijiazhuang"} > D1 {'Zhejiang': 'Hangzhou' 'Jiangsu': 'Nanjing'} > d1.update (d2) > > D1 {Zhejiang: Hangzhou, Jiangsu: Nanjing, Shandong: Jinan, Hebei: Shijiazhuang} > > d3 = {Zhejiang: Hangzhou * > > D1 {Zhejiang: Hangzhou, Jiangsu: Nanjing 'Shandong': 'Jinan', 'Hebei': 'Shijiazhuang'} > d1.update (d3) > > D1 {'Zhejiang': 'Hangzhou *', 'Jiangsu': 'Nanjing', 'Shandong': 'Jinan', 'Hebei': 'Shijiazhuang'} > Thank you for your reading The above is the content of "how to use the update () method of the Python dictionary". After the study of this article, I believe you have a deeper understanding of how to use the update () method of the Python dictionary. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Hangzhou Jiangsu Zhejiang Dictionary Nanjing method Shandong Hebei Jinan Shijiazhuang Shijia object Learning content Hangzhou Update iteration Code keyword Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple Docker Shulou Technology OPPO Reno