[Tutor] Counting a string backwards
tmrsg11 at gmail.com
Sun May 28 20:11:35 EDT 2017
Thank you very much, I got it. So in this case, there is no need to specify
where it ends.
In fact, even if I wanted to specify the ending, I can't!
On Sun, May 28, 2017 at 7:19 PM, Alan Gauld via Tutor <tutor at python.org>
> On 28/05/17 18:58, C W wrote:
> > Now if I do case 2,
> >> print(great[-3:-1])
> >> me
> > Where did the exclamation mark go in case 2?
> > I was told the count begins at zero, that's true going forward, but not
> > backwards.
> Its not about where the count starts its about where it finishes.
> It finishes 1 item before the second index. so in this case
> you get the items at -3 and -2.
> If you specify a third parameter you can change the
> direction of the count thus:
> >>> great[-1:-3:-1]
> So now you get the characters at -1 and -2 (ie in reverse order)
> If you want them in original order starting at -3 just omit
> the -1:
> >>> great[-3:]
> Alan G
> Author of the Learn to Program web site
> Follow my photo-blog on Flickr at:
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
More information about the Tutor