[Tutor] What exactly does the three dots do? Why such as thing?

Steven D'Aprano steve at pearwood.info
Thu Aug 10 08:47:59 EDT 2017


On Wed, Aug 09, 2017 at 12:06:37PM -0400, C W wrote:
> Dear Python experts,
> 
> What exactly does the three dots do?
> > aList = ...

... is literal syntax for the Ellipsis singleton object.

Ellipsis was added to the language at the express request of the numpy 
developers. Although numpy is a third-party project outside of the 
standard library, it is big enough and important enough that their 
requests carry a LOT of weight with the core Python devs. Other features 
Python has that were originally added at the request of numpy include:

- extended slicing with two colons obj[a:b:c]

- the @ operator used by numpy for matrix multiplication.

I don't know what Ellipsis is used for by numpy, but now it makes a 
convenient pseudo-pass command:

class X:
    ...

def func():
    ...


> It's an ellipsis, a spot holder to later. But what data type is it: vector,
> matrix?

Its a singleton object. Think of it as a sibling to None and 
NotImplemented, but with optional funny syntactic sugar ... to refer to 
it.

None is a special value used as "no such value", or nil or null;

NotImplemented is a special value used by operator dunder methods like 
__add__ and __mul__ to mean "I can't handle this argument";

Ellipsis is a special value used by numpy to mean whatever it is that 
numpy uses it to me.


-- 
Steve


More information about the Tutor mailing list