Python realizes outputting strings in reverse order

王林
Release: 2020-05-07 14:42:26
Original
8446 people have browsed it

Python realizes outputting strings in reverse order

Method for string output in reverse order:

1. Method through index

>>> strA = "abcdegfgijlk" >>> strA[::-1] 'kljigfgedcba'
Copy after login

2. Flip with the help of list

#coding=utf-8 strA = raw_input("请输入需要翻转的字符串:") order = [] for i in strA: order.append(i) order.reverse() #将列表反转 print ''.join(order) #将list转换成字符串
Copy after login

Result:

请输入需要翻转的字符串:abcdeggsdd ddsggedcba
Copy after login

Recommended tutorial:python tutorial

The above is the detailed content of Python realizes outputting strings 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!