什么意思?它有意义吗?

时间:2013-06-17 11:23:29

标签: python

我有时会看到并且不理解...的含义。三个时期。 以下是我不明白的例子:

>>> 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 个答案:

答案 0 :(得分:5)

在您的情况下,主要是为了表明您继续使用相同的代码块。但是,在Python中有一个Ellipsis对象主要用于numpy数组,但在Python3.x中,它也可用作...,因此在Python3.x解释器中键入它将返回Ellipsis ...

作为行/块继续

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

As Ellipsis(在Python 3.x中)

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

答案 1 :(得分:3)

这只是用于显示您正在继续使用相同行/块的IDE的视觉辅助。

另一个例子:

>>> x = 1 + (
... 2)