Python_API_Built-in Types_dict.update

update([other])

Update the dictionary with the key/value pairs fromother, overwriting existing keys. ReturnNone.

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).

Changed in version 2.4:Allowed the argument to be an iterable of key/value pairs and allowed keyword arguments.

update([other])
将参数other映射到dictionary中,返回None
             该方法接受另一个字典对象或一个键/值对迭代(长度为二的元组或其他iterables)。如果指定关键字参数,然后用这些键/值对更新字典:d.update(红色,蓝色= 1= 2)。    

例: #! /usr/bin/env python
#coding=utf-8

dict={'name':'lyle','id':'l'}
print type(dict)
print dict
dict.update(name=1)
print dict
a = (('a','b'),('1','2'))#注意这里必须是2个以上
dict.update(a)
print a
dict.update({'title':'title1','id':'2'})

print dict


输出: <type 'dict'>
{'name': 'lyle', 'id': 'l'}
{'name': 1, 'id': 'l'}
(('a', 'b'), ('1', '2'))
{'a': 'b', '1': '2', 'name': 1, 'title': 'title1', 'id': '2'}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值