Created
June 5, 2013 15:37
-
-
Save ZoeyYoung/5714852 to your computer and use it in GitHub Desktop.
Reverse String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s = 'abcdefgh' | |
r = s[::-1] | |
print(r) #a : hgfedcba |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reverse(word): | |
if word == '': | |
return word; | |
return reverse(word[1:]) + word[0] | |
print(reverse('abcdefg')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment