当前位置:网站首页>List和Dict数据类型作用详解
List和Dict数据类型作用详解
2022-06-11 15:49:00 【Ethan~Noah】
一、 list列表扩展的方式有几种(或者说添加元素的方法)
(1)append(将对象追加到末尾)
(2)extend(通过从可迭代对象追加元素来扩展列表)
(3)insert(在索引之前插入对象 ,即扩展列表 )
2. 对["cherry", "litchi", "strawberry", "mangosteen", "pomelo", "pineapple", "pitaya", "durian"]进行默认排序
对上面的列表使用第三个字母进行排序

3. dict中所有方法的使用(先写源代码再写样例)
(1) clear(...)
D.clear() -> None. Remove all items from D.
删除所有项目

(2)copy(...)
D.copy() -> a shallow copy of D
浅拷贝复制

(3) get(self, key, default=None, /)
Return the value for key if key is in the dictionary, else default.
如果 key 在字典中,则返回 key 的值,否则返回默认值。

(4)items(...)
D.items() -> a set-like object providing a view on D's items
将数据类型进行转换

(5) keys(...)
D.keys() -> a set-like object providing a view on D's keys
提取除字典中所有的key值

(6)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
如果未找到 key,则返回 default(如果给定),否则引发 KeyError

(7)popitem(self, /)
| 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。

(8)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 的值,否则返回默认值。

(9)update(...)
| D.update([E, ]**F) -> None. Update D from dict/iterable E and F.
D.update([E, ]**F) -> None. 从字典/可迭代 E 和 F 更新 D。
| If E is present and has a .keys() method, then does: for k in E: D[k] = E[k]
如果 E 存在并且具有 .keys() 方法,则对于 E 中的 k:D[k] = E[k]
| If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v
如果 E 存在并且缺少 .keys() 方法,则对于 E 中的 k, v:D[k] = v
| In either case, this is followed by: for k in F: D[k] = F[k]
在任何一种情况下,这后面跟着:对于F中的k:D[k] = F[k]

(10)values(...)
| D.values() -> an object providing a view on D's values
D.values() ->一个对象,提供 D 的值

边栏推荐
- Detailed explanation of opengauss multi thread architecture startup process
- Database resource load management (Part 1)
- GO语言数组和切片的区别
- 【愚公系列】2022年06月 .NET架构班 076-分布式中间件 ScheduleMaster的执行原理
- Nat commun | language model can learn complex molecular distribution
- openGauss简单查询SQL的执行流程解析
- openGauss 多线程架构启动过程详解
- From 0 to 1, master the mainstream technology of large factories steadily. Isn't it necessary to increase salary after one year?
- Tianjin Port coke wharf hand in hand map flapping software to visually unlock the smart coke port
- rf中安装的第四步:安装 robotframework-selenium2library报错
猜你喜欢

This "invisible" robot may be your future colleague

PostgreSQL startup process

使用Cloud DB构建APP 快速入门-快应用篇

收藏 |彻底搞懂感受野的含义与计算

Nat commun | language model can learn complex molecular distribution

从屡遭拒稿到90后助理教授,罗格斯大学王灏:好奇心驱使我不断探索

GO语言-Slice切片

推开混合云市场大门,Lenovo xCloud的破局之道

MAUI 入门教程系列(1.框架简介)

openGauss数据库JDBC环境连接配置(Eclipse)
随机推荐
With an average annual salary of 20W, automated test engineers are so popular?
Golang map basic operations
[golang] leetcode special training - array and slice
GO语言-值类型和引用类型
验证码是自动化的天敌?阿里研究出了解决方法
How to predict SQL statement query time?
YEF 2022昨日开幕,多网络平台全程免费直播,开启在线技术盛宴!
Verification code is the natural enemy of automation? Ali developed a solution
CLP information - financial standardization "14th five year plan" highlights data security
【愚公系列】2022年06月 .NET架构班 076-分布式中间件 ScheduleMaster的执行原理
Factory calibrated gravity: working principle and installation position of carbon monoxide sensor, calibration standard description
openGauss数据库JDBC环境连接配置(Eclipse)
前沿科技探究之AI工具:Anomaly-detection
Go language - value types and reference types
Frontier technology exploration deepsql: in Library AI algorithm
Elk enterprise log analysis system
Performance of MOS transistor 25n120 of asemi in different application scenarios
openGauss并行解码浅谈
导入数据:gs_restore or MERGE INTO? 看看哪款更适合你
从屡遭拒稿到90后助理教授,罗格斯大学王灏:好奇心驱使我不断探索