Re: [Tutor] Counting a string backwards

2017-05-29 Thread C W
Wow, that's the best explanation I've seen so far, now it's gonna stick with me! Thank you! On Sun, May 28, 2017 at 10:00 PM, Steven D'Aprano wrote: > On Sun, May 28, 2017 at 01:58:22PM -0400, C W wrote: > > Dear Python list, > > > > I am having trouble understanding the following. > [...] > >

Re: [Tutor] Counting a string backwards

2017-05-29 Thread C W
Hi Alan 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! Thank you! On Sun, May 28, 2017 at 7:19 PM, Alan Gauld via Tutor wrote: > On 28/05/17 18:58, C W wrote: > > > Now if I do case 2, > >> p

Re: [Tutor] Counting a string backwards

2017-05-28 Thread Peter Otten
Steven D'Aprano wrote: > Because 0 always means the start of the string, how do you slice to the > end? You can use the length of the string (in this case, 7) or you can > leave the ending position blank, and it defaults to the length of the > string: For completeness, there's a third option, Non

Re: [Tutor] Counting a string backwards

2017-05-28 Thread Steven D'Aprano
On Sun, May 28, 2017 at 01:58:22PM -0400, C W wrote: > Dear Python list, > > I am having trouble understanding the following. [...] The way to think about string indexing and slicing is that the index positions mark *between* the characters. Take your string: Machine learning is awesome!

Re: [Tutor] Counting a string backwards

2017-05-28 Thread Alan Gauld via Tutor
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 finishe

[Tutor] Counting a string backwards

2017-05-28 Thread C W
Dear Python list, I am having trouble understanding the following. If I do case 1, great = "Machine learning is awesome!" > print(great[-1]) > ! 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 fo