[docs] Python doc bug?

Sandro Tosi matrixhasu at gmail.com
Tue Mar 6 21:38:02 CET 2012


Hello David,
I think this question fits more closely to the scope of python-list:
http://mail.python.org/mailman/listinfo/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:
> 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:

did you read the doc about strings slicing at
http://docs.python.org/tutorial/introduction.html#lists ?

>>>> a[1:-1]
>
> ['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?

see above.

Cheers,
-- 
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 mailing list