python 列表的方法
来源:互联网 发布:淘宝男士帽子专卖店 编辑:程序博客网 时间:2024/06/08 03:18
【1】列表添加:
(1)append() 向列表尾部添加数据,例如下:
demo:
(2)extend()将一个集合里面的数据逐一添加到另一集合里面去(也是在列表尾部添加),例如下:
demo:
(3)insert(index,object)将数据添加到知道的下标位置,将object的数据添加到index下标位置去:
demo:
【2】修改元素
根据下标修改数据
demo:
【3】查找元素
(1)in 存在 返回True或者False
demo:
list = ['ni','hao','world']
name = input('请输入您要查询的内容')
if name in list:
print('存在')
(2)not in 不存在 返回True或者False
demo:
list = ['ni','hao','world']
name = input('请输入您要查询的内容')
if name not in list:
print('不存在')
(3)index(object,index,index) 找到元素在下标为几的下面(左闭右开)
demo:
(4)count 查找元素的个数
demo:
【4】删除元素
(1)del:根据下标进行删除
demo:
del 列表名称[下标]
(2)pop:删除最后一个元素,并返回删除的元素
demo:
(3)remove:根据元素的值进行删除
【5】排序(sort, reverse)
(1)sort:sort方法是将list按特定顺序重新排列,默认为由小到大,参数reverse=True可改为倒序,由大到小
demo:
倒序:
(2)reverse 将list逆置(列表反转):
demo:
阅读全文
0 0
- python 列表的方法
- Python列表的方法
- python列表的排序方法
- Python列表的常用方法
- python列表和字典的方法总结
- Python 列表和字典的一些方法
- Python列表和字典的方法总结
- python 分割列表的几种方法
- python列表和字典的方法总结
- python中列表的常用方法
- [Python]列表复制的几种方法
- python中复制列表的正确方法
- python的列表list方法大全
- Python中列表对象的方法
- python中列表的常用方法
- Python合并两个列表的方法
- python 中列表的sort方法
- Python中列表常用的方法
- 用Epoll实现简单C++服务器
- 为什么这个电路的MOS容易失效?
- SSM框架整合过程中,Mybatis报错
- D01 linux基础及其虚拟机下网络模式
- C++实现协程调度
- python 列表的方法
- ok请求加载数据
- 设计模式C++版:第十八式备忘录模式
- BZOJ 2212: [Poi2011]Tree Rotations 线段树合并
- zookeeper的java API 接口(一)
- Android 防止启动页面(SplashActivity)被多次启动(笔记)
- Yii2.0小部件GridView(两表联查/搜索/分页)②
- D02 Linux基础
- 母牛的故事