learning_python_list
数据结构
-
python 中的数据结构
-
不可变类型
- int:整型
- float:浮点型
- bool:布尔型
- str:字符串
-
可变类型
- list:列表
- tuple:元组
- set:集合
- dict:字典
-
- 获取数据类型:
type()
如:
In [1]: type(1) Out[1]: int In [2]: type(1.1) Out[2]: float In [3]: type(True) Out[3]: bool In [3]: type(False) Out[3]: bool
列表
- 列表(list)(
[]
)是一种存储大量数据的存储模型,可以对数据进行增、删、改、查操作。 -
增加数据
- append(self, object): Append object to the end of the list.
- insert(self, index, object): Insert object before index.
- extend(self, iterable): Extend list by appending elements from the iterable.
- 翻译:
- append(self, object): 在列表的末尾添加元素。
- insert(self, index, object): 在指定位置之前插入元素。
- extend(self, iterable): 从可迭代数据存储器中扩充到列表末尾。
-
删除数据
- remove(self, object): Remove first occurrence of value.Raises ValueError if the value is not present.
- pop(self, index): Remove and return item at index (default last).Raises IndexError if list is empty or index is out of range.
- clear(self): Remove all items from list.
- 翻译:
- remove(self, object): 移除列表中第一个指定数据,若指定数据不存在,抛出ValueError。
- pop(self, index): 移除并返回列表中指定位置的数据(默认为最后一个),若列表为空或者指定位置超过范围,抛出IndexError。
- clear(self): 移除列表中所有元素。
- 修改数据和查询数据:根据索引
-
其他函数
- count(self, object): Return number of occurrences of value.
- index(self, object, start, stop): Return first index of value.Raises ValueError if the value is not present.
- copy(self): Return a shallow copy of the list.
- reverse(self): Reverse IN PLACE.
- sort(self, key, reverse): Stable sort IN PLACE.
- 翻译
- count(self, object): 返回指定数据在列表中的个数。
- index(self, object, start, stop): 返回指定数据在列表中第一个位置,若指定数据不存在,抛出ValueError。
- copy(self): 返回一个列表的拷贝。
- reverse(self): 在列表上反转。
- sort(self, key, reverse): 在列表上执行稳定排序。
感谢阅读,本文首发于 learning_python_list。
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
nginx的安装和配置
仅供参考, 不同系统操作可能会不一样, 中间遇到错误, 找一下错误原因, 一般是单词”error“后的一句, 复制, 百度, vim操作下面有注释 首先是域名解析到指定的服务器 安装nginx 方法一:这个是最简单的方法,但是很有可能会失败,这里搞定了就能直接去配置nginx了 1.安装g++a sudo apt-get install g++ 2.使用apt直接安装 sudo apt-get install nginx 3.启动 service nginx start 方法二 下载nginx及相关组件输入 : cd /usr/local/src/ wget http://nginx.org/download/nginx-1.10.2.tar.gz wget http://www.openssl.org/source/openssl-fips-2.0.10.tar.gz wget http://zlib.net/zlib-1.2.11.tar.gz wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40....
- 下一篇
如何使用Visual Studio Code调试PHP CLI应用和Web应用
在按照Jerry的公众号文章 什么?在SAP中国研究院里还需要会PHP开发? 进行XDebug在本地的配置之后,如果想使用Visual Studio Code而不是Eclipse来调试PHP应用,步骤也比较简单。 启动WAMP服务器,确保xdebug.remote_autostart, xdebug.remote_enable都为on: 然后安装Visual Studio Code的扩展:PHP Debug 安装完毕后,File->Preferences->Settings: 添加一条entry:php.validate.executablePath, 指向你本地的php.exe 创建一个PHP debug configuration,有两种方式选择:Launch current open script和Listen for Xdebug: { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池
- Windows10,CentOS7,CentOS8安装Nodejs环境
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS8安装Docker,最新的服务器搭配容器使用
- 设置Eclipse缩进为4个空格,增强代码规范
- CentOS7安装Docker,走上虚拟化容器引擎之路
- SpringBoot2初体验,简单认识spring boot2并且搭建基础工程
- CentOS7设置SWAP分区,小内存服务器的救世主