Python:slice与indices的用法
作者:筱筱的春天 时间:2021-09-10 22:31:09
slice:
eg:
>>>e=[0,1,2,3,4,5,6]
>>>s=slice(2,3)
>>>e[s]
[2]
slice的区间左闭右开[)
>>>s
slice(2,3,None)
slice([strar,]stop[,step]),start缺少时就是0
indices:
eg:
>>>print(s.indices(100))
(2,3,1)
>>>print(s.indices(3))
(2,3,1)
>>>print(s.indices(2))
(2,2,1)
>>>e[s]
[2]
这个indices相当于stop的位置,只要是大于之前的stop索引,按之前的来,否则就取小索引
来源:https://www.cnblogs.com/baxianhua/p/8145324.html
标签:Python,slice,indices
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
IE下,事件触发那点破烂事儿
2009-04-27 12:31:00
python统计多维数组的行数和列数实例
2021-02-07 00:32:17
python中的实例方法、静态方法、类方法、类变量和实例变量浅析
2021-11-06 01:52:14
Python图像处理之使用OpenCV检测对象颜色
2023-05-20 01:00:18
![](https://img.aspxhome.com/file/2023/9/75089_0s.jpg)
Python TCPServer 多线程多客户端通信的实现
2021-07-05 22:33:00
![](https://img.aspxhome.com/file/2023/2/75092_0s.png)
取巧的边框等高
2009-12-16 12:11:00
![](https://img.aspxhome.com/file/UploadPic/200912/16/css_border-13s.png)
如何把URL和邮件地址自动转换为超级链接?
2009-11-02 20:22:00
Pytest mark使用实例及原理解析
2021-02-27 14:30:11
Pycharm及python安装详细教程(图解)
2023-01-06 00:26:00
![](https://img.aspxhome.com/file/2023/6/75266_0s.jpg)
如何使用数据绑定控件实现不换页提交数据?
2010-05-16 15:17:00
防采集,几种觉得有用的防采集方法
2009-09-03 13:30:00
Pycharm设置界面全黑的方法
2021-09-15 11:13:51
python多进程使用apply_async的使用方法详解
2022-11-14 16:08:50
![](https://img.aspxhome.com/file/2023/3/80813_0s.png)
不得不承认:韩国的 Web 设计很唯美
2009-05-13 13:26:00
![](https://img.aspxhome.com/file/UploadPic/20095/13/1221540-46s.jpg)
Python简单实现的代理服务器端口映射功能示例
2022-09-10 07:52:54
![](https://img.aspxhome.com/file/2023/1/93711_0s.png)
为网页设计创建有效的配色方案
2011-08-31 12:55:57
Python request设置HTTPS代理代码解析
2023-01-15 00:48:24
python调用百度API实现人脸识别
2021-06-11 23:52:23
![](https://img.aspxhome.com/file/2023/2/68472_0s.png)
Python Flask 转换器的使用详解
2023-06-30 15:42:09
![](https://img.aspxhome.com/file/2023/8/95228_0s.jpg)
ajax标签导航实例详解教程
2008-02-01 10:54:00
![](https://img.aspxhome.com/file/UploadPic/up/2008020111434016.gif)