This came up in Hidden features of Python, but I can't see good documentation or examples that explain how the feature works.

解决方案

Ellipsis, or ... is not a hidden feature, it's just a constant. It's quite different to, say, javascript ES6 where it's a part of the language syntax. No builtin class or Python language constuct makes use of it.

So the syntax for it depends entirely on you, or someone else, having written code to understand it.

Numpy uses it, as stated in the documentation. Some examples here.

In your own class, you'd use it like this:

>>> class TestEllipsis(object):

... def __getitem__(self, item):

... if item is Ellipsis:

... return "Returning all items"

... else:

... return "return %r items" % item

...

>>> x = TestEllipsis()

>>> print x[2]

return 2 items

>>> print x[...]

Returning all items

Of course, there is the python documentation, and language reference. But those aren't very helpful.

python切片语法-如何在Python中使用省略号切片语法?相关推荐

  1. python中换行符怎么写_语法 - 如何在Python中执行换行符(换行符)?

    语法 - 如何在Python中执行换行符(换行符)? 我有一长串代码,我希望在多行之间分解. 我使用什么,语法是什么? 例如,添加一串字符串, e = 'a' + 'b' + 'c' + 'd' 并将 ...

  2. python pop() ,如何在Python的列表或数组中移除元素

    python pop() ,如何在Python的列表或数组中移除元素 在本文中,你将学习如何使用Python内置的 pop() 方法,最后,你将知道如何使用 pop() 从 Python 中的列表中删 ...

  3. python大括号_如何在python字符串中打印文字大括号字符并在其上使用.format?

    如何在python字符串中打印文字大括号字符并在其上使用.format? x = " \{ Hello \} {0} " print x.format(42) 给我:{Hello} ...

  4. python调用soap_如何在python zeep中调用soap api而不使用wsdl(非wsdl模式)?使用用户和密码身份验证调用位置URL...

    我无法在Zeep python客户端中为SOAP API验证用户身份 . 我有两个网址: 1) http://credotrade.stg-tradingcrm.com:8093/mex - 它指定了 ...

  5. python hadoop streaming_如何在Hadoop中使用Streaming编写MapReduce(转帖)

    作者:马士华 发表于:2008-03-05 12:51 最后更新于:2008-03-25 11:18 版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息. http://www ...

  6. python多项式回归_如何在Python中实现多项式回归模型

    python多项式回归 Let's start with an example. We want to predict the Price of a home based on the Area an ...

  7. python使用spark_如何在Python中编写简单代码,并且速度超越Spark?

    全文共3482字,预计学习时长7分钟 如今,大家都在Python工具(pandas和Scikit-learn)的简洁性.Spark和Hadoop的可扩展性以及Kubernetes的操作就绪之间做选择. ...

  8. spyder python 使用_如何在spyder中使用vpython?

    我试着用vpython,无论如何,但我失败了...在 首先,我在win8.1上安装了anacondapython2.7.10. 然后,我通过在命令行中输入以下命令来安装Vpython: conda安装 ...

  9. vscode怎么安装python库_如何在vscode中安装python库的方法步骤

    免费资源网 - https://freexyz.cn/ vscode安装python库 1.已经在vscode中装了python并配置好python运行环境. 检查是否正确配置好运行环境,按Windo ...

  10. 【Python】Windows如何在cmd中切换python版本

    相信很多小伙伴都会有像我一样经历,在windows中装了很多python版本,那么如果我们正式使用的时候应该如何切换呢? [方法一]从环境变量中切换python 第一步: 打开环境变量 第二步:打开系 ...

最新文章

  1. iphone11看信号强度_iPhone11信号怎么样_iPhone11信号差原因|解决办法-太平洋IT百科...
  2. python【数据结构与算法】最短路算法之FloyedDijkstra
  3. Android7.1图标快捷方式(AppShortcuts)实现Demo
  4. 解决ubuntu修改密码 Module is unknow报错
  5. python桌面程序开发_程序员之路:python3+PyQt5+pycharm桌面GUI开发
  6. JDK,JRE,JVM三者的关系
  7. Codeforces 835 F Roads in the Kingdom(树形dp)
  8. Session一次错误记录
  9. 取暖器外贸出口到欧洲申请欧盟CE认证指令标准解析
  10. pimple idiom
  11. 【HBuilderX】预编译器错误:代码使用了scss/sass语言,但未安装相应的编译器插件,请前往插件市场安装该插件:
  12. 自定义java对象转换工具类
  13. C#语言入门详解1-12
  14. cl.clcl.news/index.php,公布一些后门网址
  15. 陆道培医疗冲刺香港上市:持续亏损,毛利率下滑,陆佩华为董事长
  16. 目标检测——梯度均衡机制GHM(Gradient Harmonized Mechanism)的理解
  17. 阿里巴巴内测全网社交产品来往
  18. 论文笔记:DLWL: Improving Detection for Lowshot classes with Weakly Labelled data
  19. 热评云厂商:蓝汛4.0亿元,如何扭转乾坤看转型与创新
  20. Uber 新冠之殇:首席技术官Thuan Pham宣布离职,预计裁员5400人

热门文章

  1. [Java]Thinking in Java 练习2.10
  2. xcodeproj cannot be opened because the project file cannot be parsed.
  3. 解决yum安装时 Cannot retrieve repository metadata (repomd.xml) for repository
  4. document.compatMode属性
  5. Error: Could not access the Package Manager. Is the system running?
  6. C# 二种方法控制系统音量/麦克风大小
  7. 吉他入门第一讲~~~~~右手弹奏基础
  8. 自动化工具之二:win32gui
  9. Maven最佳实践-distributionManagement
  10. JAVA中用 SQL语句操作小结