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

Steven D'Aprano steve at pearwood.info
Fri Aug 11 21:24:05 EDT 2017


On Fri, Aug 11, 2017 at 07:57:09AM -0600, Mats Wichmann wrote:
> On 08/10/2017 05:23 PM, Alan Gauld via Tutor wrote:
> > On 10/08/17 14:39, C W wrote:
> > 
> >> I suppose it's just a place holder, though I don't know when I would use it
> >> in my every day life.
> > 
> > Probably never.
> > 
> > Like most programming languages Python has a load of rarely used,
> > obscure features. Most Python programmers never use ellipses,
> 
> I guess what this means is when I post code snippets with some lines
> elided for greater readability of the point being made I should not use
> ellipses for that, as they're actually a syntactic element!   :)

No, go right ahead and continue using ... for elided lines. Python 3 
makes that syntactically legal, and the fact that elided code may be 
syntactically correct is one of the reasons that was done.

In Python 2, ... was just the *display* form of Ellipsis, and wasn't 
legal except in slice notation: a[...]. Python 3 made ... syntactic 
sugar for Ellipse everywhere, not just in slices, which makes:

    x = ...

    class X:
        ...

perfectly legal code. (Perhaps not *meaningful* code, but that's okay.)


-- 
Steve


More information about the Tutor mailing list