python implements string output in reverse order

王林
Release: 2020-05-08 14:01:57
Original
14668 people have browsed it

python implements string output in reverse order

Python has two ideas for realizing string output in reverse order:

1. Write a loop to implement

Take one character of the string each time, from It can be taken from the last to the front and can be output directly, or it can be added to a new string and output together at the end.

Specific code:

m = list(a) for i in range(len(a)-1,-1,-1): print(m[i],end = '')
Copy after login

2. Use slicing to implement

print(a[::-1])
Copy after login

Recommended tutorial:python tutorial

The above is the detailed content of python implements string output in reverse order. 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
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!