[Tutor] slicing a string

lists lists at justuber.com
Tue Sep 7 00:45:20 CEST 2010


>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
>>> doesn't work (as I expected it to) but that mytext[::-1] does.
>>>
>>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work?
>>
>> How does it not "work"? What did you expect to happen? What did it do instead?
>>
>> Greets
>> Sander
>>
>
> Hi, assuming mytext is "test", word[-1:-4:-1] returns tse
>
> My understanding of how the index works on test would be:
>
> 0  1  2  3
> t   e  s   t
> -4 -3 -2 -1
>
> So I just wasn't clear on what happened to the last 't' I expected to see.
>
> Cheer,
>
> Chris
>

Sorry I mean mytext[-1:-4:-1] not word[-1:-4:-1] :-S


More information about the Tutor mailing list