字典update方法

car = {
    "brand": "Porsche",
    "model": "911",
    "year": 1963
}

car.update({"age": 180}, d={"brand": 18})
print(car)  # {'brand': 'Porsche', 'model': '911', 'year': 1963, 'age': 180, 'd': {'brand': 18}}
car.update({"brand": "python"}, a=1)  # 有则修改,无则增加
print(car)  # {'brand': 'python', 'model': '911', 'year': 1963, 'age': 180, 'd': {'brand': 18}, 'a': 1}
car.update(zip(['eleven', 'twelve'], [11, 12]))
print(car)  # {'brand': 'python', 'model': '911', 'year': 1963, 'age': 180, 'd': {'brand': 18}, 'a': 1, 'eleven': 11, 'twelve': 12}
posted @ 2022-07-25 00:24  我是小菜鸡丫丫  阅读(86)  评论(0)    收藏  举报