Created
December 5, 2019 01:32
-
-
Save FerdinaKusumah/1e9ccbf7a7cb876fa4df4130c2ec6e42 to your computer and use it in GitHub Desktop.
Reverse String
This file contains hidden or 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
"""Reverse string""" | |
a = "python" | |
reversed_words = a[::-1] | |
print("reversed {} to {}".format(a, reversed_words)) | |
# reversed python to nohtyp | |
"""Reverse number""" | |
b = 123456789 | |
reversed_num = str(b) | |
print("reversed {} to {}".format(b, reversed_num)) | |
# reversed 123456789 to 123456789 | |
"""Iterate over reversed string efficiently""" | |
for words in reversed(a): | |
print(words) | |
# n | |
# o | |
# h | |
# t | |
# y | |
# p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment