1. 使用字符串切片,步长设置为-1
1 # coding:utf-8 2 3 s = “abcdefg123” 4 r = s[::-1] 5 print(r)
2. 双端队列
1 # coding:utf-8
2 from collections import deque
3
4
5 def string_reverse4(string):
6 d = deque()
7 d.extendleft(string)
8 print ''.join(d)
9
10
11 string_reverse4("abcdefg123")
3. 使用列表的reverse方法
1 # coding=utf-8 2 3 m = list(s) 4 m.reverse() 5 result = "".join(m)
使用列表的reverse方法
使用字符串切片
来源:https://www.cnblogs.com/chenpengzi/p/11251512.html