[docs] Python doc bug?

David Arendash arendash at fxpal.com
Tue Mar 6 03:28:21 CET 2012


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.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20120305/ea51f97b/attachment.html>


More information about the docs mailing list