Python切片操作
来源:互联网 发布:python re 匹配域名 编辑:程序博客网 时间:2024/06/04 19:17
Python切片操作可以截取元组和列表的一部分元素。通常的格式为:
[起始下标:终止下标+1 :步长]
注意:元组和列表的第一个下标是0
a = [1, 2, 3, 4, 5]a[0:4:1]Out[43]: [1, 2, 3, 4]a[0:5:1]Out[44]: [1, 2, 3, 4, 5]a[1:4]Out[45]: [2, 3, 4] #步长可以缺省a[0:5:2]Out[46]: [1, 3, 5] a[:4]Out[47]: [1, 2, 3, 4] #起始下标可以缺省a[2:]Out[48]: [3, 4, 5] #终止下标可以缺省a[2::2]Out[49]: [3, 5] a[::-2]Out[50]: [5, 3, 1] #-2表示倒着数a[-2:0]Out[51]: [] #默认步长1,因此输出为空a[-2:0:-1]Out[52]: [4, 3, 2] #可设置步长为-1,表示倒着数
0 0
- Python 切片操作
- python切片操作
- 【Python】切片操作符
- python-切片操作符
- Python切片操作
- python 切片操作
- python切片操作
- python中的切片操作
- python切片操作
- Python的切片操作
- Python切片操作
- Python—切片操作
- Python切片赋值操作
- Python切片操作
- PYTHON之切片操作
- python之切片操作
- python中的切片操作
- python中的切片操作符
- 数据库查询优化策略
- 使用protobuf作为http通讯格式
- ViewGroup的触摸事件的传递源码详细解析
- android 清理进程数据
- Jave String StringBuffer StringBuilder杂想
- Python切片操作
- ssm用ehcache会出现的错误
- spring中bean的作用域
- python学习之路——函数参数问题
- ggplot2学习
- 浅谈JavaScript对象数组根据某属性sort升降序排序
- 解读机器学习基础概念:VC维的来龙去脉
- "viewport" content="width=device-width
- Machine Learning第六讲[应用机器学习的建议] --(五)使用大的数据集