Python string reverse

巴扎黑
Release: 2016-12-07 10:23:46
Original
1308 people have browsed it

Python string reversal
1. Python character to slice implementation

Python code

name = tramp  
print name[::-1]
Copy after login



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
Copy after login


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!