print command don't work (subscripted) word[2:4]
skip at pobox.com
skip at pobox.com
Tue Oct 7 15:19:32 EDT 2008
gcmartijn> Why is this not working ?
gcmartijn> bla = 'hondenriem'
gcmartijn> print bla[0:4] # correct ! (= hond)
gcmartijn> print bla[3:2] # nothing ! (= en)
gcmartijn> print bla[6:3] # nothing ! (= riem)
gcmartijn> Why don't bla[3:2] and bla[6:3] won't work ?
Because those two examples define zero-length slices (left index <= right).
The second number in each slice specification is the ending index of the
slice, not the desired length.
>>> bla = 'hondenriem'
>>> print bla[0:4]
hond
>>> print bla[3:2]
>>> print bla[2:3]
n
>>> print bla[6:3]
>>> print bla[3:6]
den
>>> print bla[3:3]
Skip
More information about the Python-list
mailing list