python字符串反转

python 字符串反转 1. python 字符转切片实现

python代码

name = tramp
print name[::-1]

2. python 递归实现

python代码

def reverse(astr):
“””reverse a string”””
if len(astr) == 0:
return astr
newstr = reverse(astr[1:]) + astr[0]
return newstr

Posted in 未分类

发表评论