Method for string output in reverse order:
1. Method through index
>>> strA = "abcdegfgijlk" >>> strA[::-1] 'kljigfgedcba'
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转换成字符串
Result:
请输入需要翻转的字符串:abcdeggsdd ddsggedcba
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!