[docs] Python doc bug?
Georg Brandl
georg at python.org
Tue Mar 6 21:40:04 CET 2012
Hi David,
you can call the second index the "end-index", but the thing to remember is
that it is never included. You can imagine the indices being "between" the
items, like this:
x = | a | b | c | d | e |
0 1 2 3 4 5
-5 -4 -3 -2 -1
so x[1:3] is [b, c] and x[1:-1] is [b, c, d].
cheers,
Georg
On 06.03.2012 03:28, David Arendash wrote:
> http://docs.python.org/tutorial/introduction.html#lists
>
> I’m new to Python, so I’m trying to understand this list index stuff, but it
> looks to me like:
>
> *>>> *a = ['spam', 'eggs', 100, 1234]
>
> *>>> *a
>
> ['spam', 'eggs', 100, 1234]
>
> Like string indices, list indices start at 0, and lists can be sliced,
> concatenated and so on:
>
>> >>
>
> *>>> *a[0]
>
> 'spam'
>
> *>>> *a[3]
>
> 1234
>
> *>>> *a[-2]
>
> 100
>
> *>>> *a[1:-1]
>
> ['eggs',*100*] Shouldn’t that last item be 1234?
>
> *>>> *a[:2] + ['bacon', 2*2]
>
> ['spam', 'eggs', 'bacon', 4] Isn’t [:2] to mean‘from start (0) to 2, thus first 3 elements, so should be 100 between eggs an bacon?
>
> *>>> *3*a[:3] + ['Boo!']
>
> ['spam', 'eggs', 100, 'spam', 'eggs', 100, 'spam', 'eggs', 100, 'Boo!']Doesn’t [:3] mean‘from 0 to 3’ thus 4 items should be repeated?
>
> It looks like whoever wrote this intended the number after the colon to mean
> ‘count’, but according to this: http://www.korokithakis.net/tutorials/python/
>
> the number after the colon is the end-index. If it were the count, the first
> line I’ve highlighted would make no sense at all.
More information about the docs
mailing list