Python第四天

1. list列表扩展的方式有几种(或者说添加元素的方法)

(1)append(self, object, /) 追加

(2) extend(self, iterable, /) 扩展

(3)insert(self, index, object, /) 插入


2. 对["cherry", "litchi", "strawberry", "mangosteen", "pomelo", "pineapple", "pitaya", "durian"]进行默认排序


    对上面的列表使用第三个字母进行排序

 


3. dict中所有方法的使用(先写源代码再写样例)

  clear(...) 清空
 |      D.clear() -> None.  Remove all items from D.
 |  
 |  copy(...) 
 |      D.copy() -> a shallow copy of D
 |  
 |  get(self, key, default=None, /)
 |      Return the value for key if key is in the dictionary, else default.
 |  
 |  items(...)
 |      D.items() -> a set-like object providing a view on D's items
 |  
 |  keys(...)
 |      D.keys() -> a set-like object providing a view on D's keys
 |  
 |  pop(...)
 |      D.pop(k[,d]) -> v,  remove specified key and return the corresponding value.移除指定的键并返回相应的值。
 |      
 |      If key is not found, default is returned if given, otherwise KeyError is raised
 |  
 |  popitem(self, /)返回并删除字典中的最后一对键和值
 |      Remove and return a (key, value) pair as a 2-tuple.
 |      
 |      Pairs are returned in LIFO (last-in, first-out) order.
 |      Raises KeyError if the dict is empty.
 |  
 |  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.
 |      如果 key 在字典中,返回 key 的值,否则默认值。

 

 

 

 

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值