Home>Article>Backend Development> python implements string output in reverse order

python implements string output in reverse order

王林
王林 Original
2020-05-08 14:01:57 14689browse

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 = '')

2. Use slicing to implement

print(a[::-1])

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!

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