Home > Article > Backend Development > Python string reverse
Python string reversal
1. Python character to slice implementation
Python code
name = tramp print name[::-1]
2. Python recursive implementation
Python code
def reverse(aStr): """reverse a string""" if len(aStr) == 0: return aStr newStr = reverse(aStr[1:]) + aStr[0] return newStr