python函数回顾:slice()
2018-05-02 15:40
260 查看
描述
slice() 函数实现切片对象,主要用在切片操作函数里的参数传递。
语法
class slice(stop) class slice(start, stop[, step])
参数说明:
- start -- 起始位置
- stop -- 结束位置
- step -- 间距
返回值
返回一个切片对象。
实例
>>>myslice = slice(5) # 设置截取5个元素的切片 >>> myslice slice(None, 5, None) >>> arr = range(10) >>> arr [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> arr[myslice] # 截取 5 个元素 [0, 1, 2, 3, 4] >>>
相关文章推荐
- python函数回顾:min()
- python函数回顾:dir()
- Python 内建函数 - slice(stop)
- python函数回顾:hex()
- Python回顾与整理9:函数和函数式编程
- python函数回顾:getattr()
- Python 函数 -slice()
- python函数回顾:abs()
- python函数回顾:setattr()
- python函数回顾:next()
- python函数回顾:all()
- kNN算法实现,及python库和函数的使用方法回顾
- python函数回顾:dict()
- python函数回顾:help()
- 走进Python世界(9)----函数
- python中常见的数学函数
- python中bool函数的取值
- python与函数
- Python 3语法小记(七)函数
- 通过python 修饰器实现对不稳定函数进行重试的功能