Home >Backend Development >Python Tutorial >python string reverse

python string reverse

PHP中文网
PHP中文网Original
2017-07-09 18:13:471558browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn