Python第五天

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.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值