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

Ben Finney ben+python at benfinney.id.au
Wed Aug 9 20:33:06 EDT 2017


C W <tmrsg11 at gmail.com> writes:

> Dear Python experts,
>
> What exactly does the three dots do?

As you've summarised: they specify a literal ellipsis object.

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

I'm not sure what form you want the answer to take.

The most obvious form is: find out by asking Python what the type is.

    >>> type(...)
    ellipsis

So, that's what type it is.

> In every other language, you initialize a variable you want to use.

Python does not have variables like that; I think it's a mistake to
re-use the term “variable” because it has that baggage.

Instead, what Python has are references to objects.

Some of those references are names. (Others examples are the references
that comprise a collection of objects.)

References *never* know the type of the object, and never need to be
initialised.

For a great comprehensive discussion, see Ned Batchelder's presentation
<URL:https://nedbatchelder.com/text/names.html> that will hopefully
dispel myths about Python names and objects.

> What's the point of ellipsis?

Similar to Python's type annotations, there is no rigid definition: it
is a lexical feature that allows implementations to choose their own
meaning.

The third-party NumPy assigns meaning to an ellipsis; you can learn
about the array slicing features of NumPy if you care to. If not, just
know that there is a point to it :-)

-- 
 \     “Pinky, are you pondering what I'm pondering?” “I think so, but |
  `\          where will we find an open tattoo parlor at this time of |
_o__)                                   night?” —_Pinky and The Brain_ |
Ben Finney



More information about the Tutor mailing list