python string reverse

PHP中文网
Release: 2017-07-09 18:13:47
Original
1508 people have browsed it

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>
Copy after login

The above is the detailed content of python string reverse. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!