Maybe someone can explain why a particular slice operation to reverse a string doesn t work. There must be something about slices I don t understand. Basic operation: s[start:end:step]
有
s= abcd
扭转这种说法,我可以采用缺省值。
s[::-1]
或
s[-1::-1]
这些是罚款,但为什么是罚款。
s[-1:-1:-1]
work and give me the whole string reversed? It should start at with the last character in the string at (-1), and the stepsize is -1. It should run down to one before -1 i.e., index 0. Instead I get .
f或i in xrange(3, -2, -1):
print s[-1:%d:-1] => %i,
print s[-1:i:-1]
产量:
s[-1:3:-1] => # didn t expect any output
s[-1:2:-1] => d
s[-1:1:-1] => dc
s[-1:0:-1] => dcb
s[-1:-1:-1] => # shouldn t this be dcba ?
我在这里失踪了吗?
(我确实看到许多关于倒塌方的布局,但如果对这个特定项目作了解释,我就没有这样做)