本文摘自php中文网,作者V,侵删。

字符串倒序输出的方法:
一、通过索引的方法
1 2 3 | >>> strA = "abcdegfgijlk"
>>> strA[::-1]
'kljigfgedcba'
|
二、借助列表进行翻转
1 2 3 4 5 6 7 | #coding=utf-8
strA = raw_input( "请输入需要翻转的字符串:" )
order = []
for i in strA:
order.append(i)
order.reverse() #将列表反转
print '' .join(order) #将list转换成字符串
|
结果:
1 2 | 请输入需要翻转的字符串:abcdeggsdd
ddsggedcba
|
推荐教程:python教程
以上就是python实现逆序输出字符串的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python中怎么运行shell脚本
Python中关于range与xrange探究详解
详解Python的基本数据类型
Python关于变量赋值的秘密介绍
Python死循环如何停止
Python利用不到一百行代码实现一个小siri
Python中怎么安装pip工具?
Python爬虫任务接单渠道
Python如何做excel自动化
Python pycurl验证basic和digest认证的方法
更多相关阅读请进入《Python》频道 >>
人民邮电出版社
python入门书籍,非常畅销,超高好评,python官方公认好书。
转载请注明出处:木庄网络博客 » python实现逆序输出字符串