Tutorial creates confusion about slices

Ant antroy at gmail.com
Wed Apr 25 03:44:20 EDT 2007


Hi Antoon,

> The best way to remember how slices work is to think of the indices as
...
>   +---+---+---+---+---+
>   | H | e | l | p | A |
>   +---+---+---+---+---+
>   0   1   2   3   4   5
>  -5  -4  -3  -2  -1
>
> This is all very well with a simple slice like:
>
>   "HelpA"[2:4]    =>     "lp"

But that is the whole point of a language tutorial, to introduce the
language and provide a way to get started. Note that the tutorial
doesn't even go into any details on extended slicing - as far as the
beginner is concerned at this point, there *is* no extended slice
notation. Even if the tutorial *did* go into more detail about
slicing, mentioning negative steps would be folly - the tutorial
should be an easy way into the language, and in such a context the
above tool for remembering how they work is just fine.

The exact (mathematical) definition for string slices is given in the
Library reference (http://docs.python.org/lib/typesseq.html), which is
where it should be. If you are at the point where understanding what
the deal is with extended slice notation for strings, then you are
ready to look at the real manual. If the tutorial was fully
comprehensive it would be massive and daunting. You'd probably have to
split it up as well, into, say, a Language reference and a Library
reference.




More information about the Python-list mailing list