str type python does not have a reverse function.
However, by stepping through the slices in reverse, we can efficiently reverse a string.
Only English characters are supported.
example:
<span style="color: #008080">1</span> a = <span style="color: #800000">'</span><span style="color: #800000">example</span><span style="color: #800000">'</span> <span style="color: #008080">2</span> b = a[::-1<span style="color: #000000">] </span><span style="color: #008080">3</span> <span style="color: #0000ff">print</span><span style="color: #000000">(b) </span><span style="color: #008080">4</span> <span style="color: #008000">#</span><span style="color: #008000">输出结果'elpmaxe'</span>
The above is the detailed content of python string reverse. For more information, please follow other related articles on the PHP Chinese website!