06-python_数据类型-列表
来源:互联网 发布:飞尸国语完整版网络 编辑:程序博客网 时间:2024/04/27 17:52
1. 引入
1.1 概念- List 是 处理一组有序项目的数据结构
- 列表 是 可变类型的数据, 即可给指定项目赋新值
- 组成: 用"[]"界定, 其项目(/元素) 用逗号 分隔.
- 举例: List1 = [1, 2, 3]
1.2 创建
1.2.1 使用[]
>>> myList = [1,2,3]
>>> myList
[1, 2, 3]
1.2.2 zip()
>>> zip([1,2], ['a','b'])
[(1, 'a'), (2, 'b')]
1.2.3 range([start,] end [,step])
>>> range(1, 10)
[1, 2, 3, 4, 5, 6, 7, 8, 9]
2. 操作
- 取值- 切片 和 索引
- list[index]
- 添加
- list.append(new) 末尾追加
- list[1:1] = [...], 在index=1 处插入
- 删除
- del(list[index])
- list.remove( list[index] | value)
- 修改
- list[index] = newValue
- 查找
- item in list
2.1 取值
>>> numList = [0, 1, 2, 3]
>>> numList[1]
1
2.2 添加
2.2.1 追加
>>> numList = [0, 1, 2, 3]
>>> numList.append(4)
>>> numList
[0, 1, 2, 3, 4]
2.2.2 插入
>>> numList = [0, 1, 2]
>>> numList[1:1] = ['a', 'b']
>>> numList
[0, 'a', 'b', 1, 2]
>>> len(numList)
5
2.3 删除
2.3.1 remove
>>> strList = ['a', 'b', 'c']
>>> strList.remove('b')
>>> strList
['a', 'c']
>>> strList.remove(strList[1])
>>> strList
['a']
2.3.2 del
>>> numList = [0, 1, 2, 3]
>>> del(1)
File "<stdin>", line 1
SyntaxError: can't delete literal
>>> del(numList[1])
>>> numList
[0, 2, 3]
2.4 查找
>>> list = ['a', 'b']
>>> list
['a', 'b']
>>> 'a' in list
True
>>> 'a' not in list
False
- 06-python_数据类型-列表
- python_列表
- Python_列表
- python_复杂数据类型
- 07-python_数据类型-字典
- [学习笔记]Python_数据类型
- python_异常列表
- Python_列表和元祖
- Python_列表生成
- python_列表生成式
- Python_操作列表
- 05-python_数据类型-元组
- 04-python_数据类型-数字和字符串
- python_忽略大小写对字符串列表排序
- python_笔记3_list列表(有序集合)
- python_利用列表练习购物系统
- python_
- 列表数据类型
- 问题3
- 道德经之踏实做人
- 网络子系统38_ip子系统初始化
- 百练2706麦森数
- 基于Android的小巫新闻客户端开发---显示新闻详细内容业务逻辑实现
- 06-python_数据类型-列表
- Java 多线程(七) 线程间的通信——wait及notify方法
- 浅析求素数算法
- HashCode的作用 以及重写equals方法为什么要重写HashCode方法?
- jquery表单验证
- 最长公共子序列(LCS)和最长公共子串(LCSubString)
- 打造属于你自己的Mac 机器人助手
- 链表的操作
- 07-python_数据类型-字典