- 论坛徽章:
- 0
|
回复 8# kingsuper_
最后一个问题:
def update(self, dict=None, **kwargs):
if dict is None:
pass
elif isinstance(dict, UserDict):
self.data.update(dict.data)
elif isinstance(dict, type({})) or not hasattr(dict, 'items'):
self.data.update(dict)
else:
for k, v in dict.items():
self[k] = v
if len(kwargs):
self.data.update(kwargs)
是否可以改成:
def update(self, dict=None, **kwargs):
if dict is None:
pass
else:
self.data.update(dict)
if len(kwargs):
self.data.update(kwargs)
我觉得是可以的:
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).
想请教一下:没有这么做的目的是?因为效率?或者?
|
|