1、切片法,直接调用库函数

class Solution:
def solve(self , str ):
# write code here
return str[::-1]

2、循环遍历

class Solution:
def solve(self , str ):
s=''
l=len(str)
for i in range(0,l):
s+=str[l-1-i]
return s

3、reverse()函数反转列表

class Solution:
def solve(self , str ):
# write code here
tempList=list(str) #字符串转为列表
tempList.reverse()
return ''.join(tempList)

4、reversed() 函数返回一个反转的迭代器,要转换的序列,可以是 tuple, string, list 或 range

class Solution:
def solve(self , str ):
# write code here
temp=reversed(str) #一个反转的迭代器
tempList=list(temp) #需要制定类型才能返回具体输出
return ''.join(tempList)