Python 字符串反转

Python 字符串反转
1. Python 字符转切片实现
name = tramp
print name[::-1]


2. Python 递归实现
def reverse(aStr):
    """reverse a string"""
    if len(aStr) == 0:
        return aStr
    newStr = reverse(aStr[1:]) + aStr[0]
    return newStr

你可能感兴趣的:(python)