python 3 中 dic 的 update 咋用?

Csuxiaowu 2011-03-05 09:55:16
RT
...全文
213 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
luotuo512 2011-03-06
  • 打赏
  • 举报
回复
http://docs.python.org.sixxs.org/release/3.1.3/library/stdtypes.html#mapping-types-dict

update([other])
Update the dictionary with the key/value pairs from other, overwriting existing keys. Return None.

update() accepts either another dictionary object or an iterable of key/value pairs (as tuples or other iterables of length two). If keyword arguments are specified, the dictionary is then updated with those key/value pairs: d.update(red=1, blue=2).

update可以接受其他的dict对象或者是可迭代的键值对做参数,如果键存在则更新对应的值,如果不存在则加入键值对到字典中。
接分,咩哈哈。

37,742

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧