python 字典修改键(key)的方法

注意:python中字典的键是不能直接修改,由于键是hash。
间接修改键的key值方法
第一种(推荐):html

dict={'a':1, 'b':2}

dict["c"] = dict.pop("a")

第二种方法:python

dict={'a':1, 'b':2}

dict.update({'c':dict.pop("a")})

第三种方法:post

dict={'a':1, 'b':2}

dict['c']=dict['a']

del dict['a']

python 字典修改键(key)的方法code

相关文章
相关标签/搜索