我有时看到...
,但不理解其含义。这是一个例子,我不理解:
>>> 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
前面是用来做什么的?我有时看到...
,但不理解其含义。这是一个例子,我不理解:
>>> 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
前面是用来做什么的?在你的情况下,主要是为了显示你正在继续同一段代码块。然而,在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
>>> x = 1 + (
... 2)