栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python第四次作业

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python第四次作业

一、list添加元素的方法:

1、append(在末尾添加对象)

2、extend(追加元素列表)

3、insert(在索引之前添加对象)

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

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

clear(...)删除所有元素

D.clear() -> None

从 D 中删除所有项目

copy(...) 拷贝
D.copy() -> a shallow copy of D
D.copy() -> D 的浅层副本 

 

 

fromkeys(*args, **kwargs)
Create a new dictionary with keys from iterable and values set to value
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 

get(self, key, default=None, /)|     

|Return the value for key if key is in the dictionary, else default.  |

pop(...)

 D.pop(k[,d]) -> v, remove specified key and return the corresponding value.

popitem(self, /)(随机删除key值)
       Remove and return a (key, value) pair as a 2-tuple.
        删除(键、值)对并将其作为 2 元组返回
      Pairs are returned in LIFO (last-in, first-out) order.
      Raises KeyError if the dict is empty.
      成对按后进先出(后进先出)顺序返回。
      如果字典为空,则引发 KeyError。 

如果字典为空,则引发 KeyError

setdefault(self, key, default=None, /)
       Insert key with a value of default if key is not in the dictionary.
        如果键不在字典中,则插入值为默认值的键 

 setdefault(self, key, default=None, /)
       Insert key with a value of default if key is not in the dictionary.
        如果键不在字典中,则插入值为默认值的键

在执行 update方法时,如果被更新的字典中己包含对应的键值对,那么原 value 会被覆盖;如果被更新的字典中不包含对应的键值对,则该键值对被添加进去。 

 

 

 

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/951896.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号