[docs] Python doc bug?
matrixhasu at gmail.com
Tue Mar 6 21:38:02 CET 2012
I think this question fits more closely to the scope of python-list:
Nonetheless, i'll try to answers your questions
On Tue, Mar 6, 2012 at 03:28, David Arendash <arendash at fxpal.com> wrote:
> 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]
> ['spam', 'eggs', 100, 1234]
> Like string indices, list indices start at 0, and lists can be sliced,
> concatenated and so on:
did you read the doc about strings slicing at
> ['eggs', 100] Shouldn’t that last item be 1234?
no because it selects from the second item to the last one *excluded*.
>>>> 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?
nope, the second element of the slice is excluded.
>>>> 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?
Sandro Tosi (aka morph, morpheus, matrixhasu)
My website: http://matrixhasu.altervista.org/
Me at Debian: http://wiki.debian.org/SandroTosi
More information about the docs