本文摘自php中文网,作者爱喝马黛茶的安东尼,侵删。

python中字符串数组如何逆序排列?下面给大家介绍几种方法:
1、数组倒序:
原始元素的倒序排列
(1)切片
1 2 3 |
|
(2)reverse()
1 2 3 4 |
|
(3)reversed(arr) #返回一个倒序可遍历对象
1 2 3 4 5 6 |
|
2、字符串倒序:
相关推荐:《Python视频教程》
(1)利用字符串截取
1 2 3 |
|
(2)利用reversed()返回倒可迭代对象(字符串实现)
1 2 3 4 5 6 |
|
(3)利用reversed()返回倒可迭代对象(数组实现)
1 2 3 4 5 6 |
|
另:
元素排序后的倒序排列:
1、sorted(...)生成新的已排列数组
sorted(iterable, cmp=None, key=None, reverse=False) --> new sorted list
2、arr.sort(...)直接操作arr,arr内元素进行正序排列
元素内的排序
param = 'hello' #返回元素内的排序
rev_str = ''.join(sorted(param)) #sorted(param)返回倒序排列的数组['e', 'h', 'l', 'l', 'o']
print rev_str ---->'ehllo'
以上就是python中字符串数组如何逆序排列的详细内容,更多文章请关注木庄网络博客!!
相关阅读 >>
Python介绍 list.sort方法和内置函数sorted
更多相关阅读请进入《Python》频道 >>

Python编程 从入门到实践 第2版
python入门书籍,非常畅销,超高好评,python官方公认好书。