Can someone explain why a particular operation to cut a string does not work. There must be something about slices that I don’t Understand. The main operation: s [start: end: step]
Considering
s='abcd'
to cancel this line i can use the defaults
s[::-1]
or
s[-1::-1]
All right, but why not
s[-1:-1:-1]
work and give me the whole chain in reverse order? It should begin with the last character in the string at (-1), and the step is -1. It should work up to one to -1, i.e. index 0. Instead, I get. ''
for i in xrange(3, -2, -1):
print 's[-1:%d:-1] => ' %i,
print s[-1:i:-1]
gives:
s[-1:3:-1] =>
s[-1:2:-1] => d
s[-1:1:-1] => dc
s[-1:0:-1] => dcb
s[-1:-1:-1] =>
What am I missing here?
(I saw a lot of messages about return lines, but if this subject was explained somewhere, I missed it)
Levon source
share