newbie string question

JohnJacob noone at here.invalid
Thu Jun 20 23:04:49 EDT 2002


"Don Low" <mt at open2web.com> wrote in message
news:aeu40s$9jg2s$1 at ID-145503.news.dfncis.de...
> There's probably a very simple explanation, but I can't see it for now, so
> bear with me.
>
> >>>pystr = 'Python'
> >>>pystr = [5]
> 'n'
> >>>pystr [2:5]
> 'tho'
>
> The question is, why isn't pystr [2:5] 'thon' instead of 'tho'. Could
> somebody explain?
>
> --
> Thanks,
>
> Mark

It's sort of analogous to time: from 2:00 to 5:00 is 3 hours. And the 5th
(zero based) hour of the day is from 5:00 to 6:00

0   1   2   3   4   5   6   7      o'clock (slicing)
| 0 | 1 | 2 | 3 | 4 | 5 | 6 |      counting the hours (indexing)
  P   y   t   h   o   n

greg





More information about the Python-list mailing list