python 字典update的用法

  • 字典 upadte 使用注意,在方法里使用 局部变量,使用update去更新值时,再次调用 会 链接到前面的值
def test02(headers = {}):
    print(headers,"start") #在没有传值 正常情况下这里打印是空的,可是使用了update 后会 把之前的数据带过来,如果参数传值后是正常的
    headers.update(x)
if __name__ == '__main__':
    test02()
    test02()

{} start
{'a': 1} start

posted on 2021-01-27 16:14  游荡的鱼  阅读(656)  评论(0编辑  收藏  举报

导航