1.dict和list中copy方法画图加代码解释
b = a.copy(): 浅拷贝, a 和 b 是一个独立的对象,但他们的子对象还是指向同一对象(是引用)
2.dict中扩展字典长度(多种方法)
def update(self, E=None, **F): # known special case of dict.update """ D.update([E, ]**F) -> None. Update D from dict/iterable E and F. If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k] """
setdefault(self, key, default=None, /)
| Insert key with a value of default if key is not in the dictionary.
|
| Return the value for key if key is in the dictionary, else default.
3.dict中获取所有的key,获取所有的value,获取所有的item
4.dict中通过一个不存在的key去获取值(要求不报错)
5.定义空集合
6.set中,求差集,求合集,求交集(要求在原集合上操作)
添加一个元素
删除一个元素(使用多种方法)
discard(...)
| Remove an element from a set if it is a member.
|
| If the element is not a member, do nothing.
pop(...)
| Remove and return an arbitrary set element.
| Raises KeyError if the set is empty.
remove(...)
| Remove an element from a set; it must be a member.
|
| If the element is not a member, raise a KeyError.