[Tutor] What exactly does the three dots do? Why such as thing?
C W
tmrsg11 at gmail.com
Sun Aug 27 14:29:30 EDT 2017
Today, I ran into ellipsis again. This time, it is COMPLETELY different
from before.
Here is a reproducible code:
import numpy as np
import matplotlib.pyplot as plt
...
x = np.linspace(0, 1)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
plt.title('Week cycle')
plt.xlabel('Month')
plt.ylabel('Price')
plt.plot(x, y)
If I leave out the ellipsis, plot title and label will not show. It's doing
interactive plot. How am I suppose to know ellipsis is doing interactive
plotting? No way I could have guessed.
Matplotlib documentation <https://matplotlib.org/> explains that it
recreated itself from Matlab plots.
Is it something similar to Matlab like
>>> hold on;
That's fine! But, how many identities will ellipsis take on? How do you
experienced users deal with these ambiguities?
On Fri, Aug 11, 2017 at 9:24 PM, Steven D'Aprano <steve at pearwood.info>
wrote:
> 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
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list