Python 字符串反转
程序员文章站
2022-05-30 15:28:45
...
Python 字符串反转
1. 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