列表 - 切片 - slice
回忆

- count是列表中的计数函数
- 列表 还可以进行什么操作 吗?🤔
帮助
- https://docs.python.org
- 搜索 list

效果
- 通用 序列 操作
- https://docs.python.org/3/library/stdtypes.html#common-sequence-operations
- 内建的 可变序列
- built-in mutable sequence

准备切片
nlist = list(range(5))
nlist

前闭后开
- 开始点
- 结束点
nlist[1:3]
nlist[1]
nlist[3]
nlist
- 前面 开始点 要包括的
- 后面 结束点 不包括的
- 所以结果是[1, 2]

切片词源
- slit
- split
- splinter
- slice
- 都是撕裂切开

面包


切片

切头

切头
clist = list("oeasy")
clist
clist[0:3]
clist[:3]
- clist[0:3]
- 就是clist[:3]
- start如果为0可省
- 从头开始

去尾

尝试
clist = list("oeasy")
clist
clist[2:5]
clist[2:8]
clist[2:]

前后都省略
clist = list("oeasy")
clist
clist[:]


切鱼

效果
clist = list("oeasy")
clist
clist[1:3]
clist[2:3]
clist[2:4]

需要转义的字符
clist = list("o\ne\tasy")
clist[1]
clist[4]
clist[1:4]

直播视频切片


尝试
nlist = list(range(5))
nlist

转化工作
nlist
nlist[-3:-1]
len(nlist)
nlist[5-3:5-1]
nlist[2:4]

给出stop
nlist
nlist[-3:5]
nlist[-3:8]

松手
nlist
nlist[-3:-1]
nlist[-3:]

空
nlist[:2]
nlist[2:]
nlist[:]

列表 切片
clist = list("oeasy")
clist[1:3]
type(clist[1:3])
clist

总结
- 索引得到的是
一个列表项
- 切片得到的是
列表项的列表
- 这两个端点 负责 位置
- start 开始 包括在内
- stop 结束 不包括在内
- 前闭后开
