[PALINDROME] Reverse a string in python.

In this code, we will take a string or a text and generate a reverse string or text.

2 solutions

# 1st way:
my_string = 'sample'
# getting last index of the string(hence -1)
length_of_string = len(my_string) - 1
# using reverse looping in range(end_index, start_index -1, step -1)
for chr in range(length_of_string,-1,-1):
#start_index -1 = iterating will stop at start_index without executing it, hence -1
# 2nd way: slice statement
my_string = 'Mr Owl ate my metal worm'
my_string = my_string[::-1]
# [::-1] means start from the end, to the first (position 0)
# step backward with (-1)

# some fun exercise, try with list
strange_sentence_list = ["Go hang a salami, I m a lasagna hog",'Do geese see God','Was it a car or a cat I saw','Murder for a jar of red rum']