Reverse a string in different ways
test_string = 'Python Programming' string_reversed = test_string[-1::-1] print(string_reversed) string_reversed = test_string[::-1] print(string_reversed) # String reverse logically def string_reverse(text): r_text = '' index = len(text) - 1 while index >= 0: r_text += text[index] index -= 1 return r_text print(string_reverse(test_string))
Sample output of above program.
gnimmargorP nohtyP
gnimmargorP nohtyP
gnimmargorP nohtyP
2018-02-12T01:40:44+05:30
2018-02-12T01:40:44+05:30
Amit Arora
Amit Arora
Python Programming Tutorial
Python
Practical Solution