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索引,按之前的来,否则就取小索引

    

Python:slice与indices的更多相关文章

  1. Python slice() 函数

    Python slice() 函数  Python 内置函数 描述 slice() 函数实现切片对象,主要用在切片操作函数里的参数传递. 语法 slice 语法: class slice(stop) ...

  2. Fluent Python: Slice

    Pyhton中序列类型支持切片功能,比如list: >>> numbers = [1, 2, 3, 4, 5] >>> numbers[1:3] [2, 3] tu ...

  3. python slice 切片

    list,tuple,string,bytes对象可以进行切片处理,生成一个新的这些类的对象. 格式:li[start: stop: step] list切片: >>> li = [ ...

  4. [Python] Slice the data with pandas

    For example we have dataframe like this: SPY AAPL IBM GOOG GLD 2017-01-03 222.073914 114.311760 160. ...

  5. Python之Numpy详细教程

    NumPy - 简介 NumPy 是一个 Python 包. 它代表 “Numeric Python”. 它是一个由多维数组对象和用于处理数组的例程集合组成的库. Numeric,即 NumPy 的前 ...

  6. python deque的内在实现 本质上就是双向链表所以用于stack、队列非常方便

    How collections.deque works? Cosven     前言:在 Python 生态中,我们经常使用 collections.deque 来实现栈.队列这些只需要进行头尾操作的 ...

  7. 《流畅的Python》 Sequence Hacking, Hashing and Slicing(没完成)

    序列修改,散列和切片 基本序列协议:Basic sequence protocol: __len__ and __getitem__ 本章通过代码讨论一个概念: 把protocol当成一个正式接口.协 ...

  8. Python SQLAlchemy --2

    本文為 Python SQLAlchemy ORM 一系列教學文: 接下來會更深入地探討查詢的使用. 查詢的基本使用法為 session.query(Mapped Class),其後可加 .group ...

  9. Python内置函数(47)——vars

    英文文档: vars([object]) Return the __dict__ attribute for a module, class, instance, or any other objec ...

随机推荐

  1. spring boot 部署

    指定运行的内存 java -Xms10m -Xmx200m -jar xxx.jar spring boot 打包成war包: 让 SpringbootApplication 类继承 SpringBo ...

  2. tomcat如何配置context的docBase

    docbase是web应用和本地路径,path是tomcat访问这个应用的URL路径.Tomcat的项目部署方式有以下三种:1.直接把项目复制到Tomcat安装目录的webapps目录中,这是最简单的 ...

  3. 无约束优化方法(梯度法-牛顿法-BFGS- L-BFGS)

    本文讲解的是无约束优化中几个常见的基于梯度的方法,主要有梯度下降与牛顿方法.BFGS 与 L-BFGS 算法. 梯度下降法是基于目标函数梯度的,算法的收敛速度是线性的,并且当问题是病态时或者问题规模较 ...

  4. background-size:100% 100% 时 background-position: % 失效

    背景知识: background-size background-position 难题: background-size 为 100% 100% 时,background-position 部分失效 ...

  5. 微信 获取wx.config 参数 基类

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  6. 金字塔原理——MECE(Mutually Exclusive Collectively Exhaustive)

    一.金字塔原理 它的样子: 一个中心思想,分出下面2到N个思想支撑,每个分论点下面又有2到N个思想(事实或数据)支撑,以此类推,形状如金字塔.原则是以终为始(先结果后原因),以上统下,归纳分组,逻辑递 ...

  7. HDU 3038 - How Many Answers Are Wrong - [经典带权并查集]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  8. python3学习笔记(7)_listComprehensions-列表生成式

    #python3 学习笔记17/07/11 # !/usr/bin/env python3 # -*- conding:utf-8 -*- #通过列表生成式可以生成格式各样的list,这种list 一 ...

  9. This version of the rendering library is more recent than your version of ADT plug-in. Please update ADT plug-in

    地址:http://stackoverflow.com/questions/18852983/eclipse-reports-rendering-library-more-recent-than-ad ...

  10. model方法取值总结

    转自:https://www.cnblogs.com/ajianbeyourself/p/3604332.html