什么是...的意思?它有什么含义吗?

3

我有时看到...,但不理解其含义。这是一个例子,我不理解:

>>> t = 12345, 54321, 'hello!'
>>> t[0]
12345
>>> t
(12345, 54321, 'hello!')
>>> # Tuples may be nested:
... u = t, (1, 2, 3, 4, 5)
>>> u
((12345, 54321, 'hello!'), (1, 2, 3, 4, 5))

这三个点号在u前面是用来做什么的?
2个回答

5

在你的情况下,主要是为了显示你正在继续同一段代码块。然而,在Python中有一个Ellipsis对象,主要用于numpy数组,在Python3.x中它也可以使用...,因此在Python3.x解释器中打字将返回Ellipsis...

作为行/块延续:

>>> if 3 > 2:
...    print 'yes' # indicates we're inside another block or continuing a statement

在 Python 3.x 中,Ellipsis的作用是:

Python 3.3.0 (default, Sep 29 2012, 17:14:58) 
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> ...
Ellipsis

3
这只是你正在使用的IDE为了显示你在继续相同的行/块而提供的视觉辅助工具。
另一个例子:
>>> x = 1 + (
... 2)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接