擅长:python、mysql、java
<p>在所有不起作用的情况下,都是从<strong>开始,然后向后移动。没有比开头更向后的了,所以你就没有更多的字符了。</p>
<p>这就是解决办法:</p>
<pre><code>>>> string[len(string)::-1]
'ydood ydwoH'
</code></pre>
<p>切片符号是<code>start</code>、<code>end</code>、<code>step</code>。当<code>step</code>为负时,<code>start</code>应该大于<code>end</code>才能得到任何结果。如果留空(<code>[::-1]</code>),则会自动跟踪细微差别</p>
<p>在您只得到<code>'H'</code>的情况下,可能会混淆为什么存在<em>anything</em>。但想想写下的解释:</p>
<blockquote>
<p>Beginning with the character at <strong>start</strong>, increment by <strong>step</strong> until (but not including) <strong>end</strong></p>
</blockquote>
<p>现在很明显,因为从0开始,0字符被包括在内</p>