1# in order to make a string reversed in python
2# you have to use the slicing as following
3
4string = "racecar"
5print(string[::-1])
6
1string = 'hello people of india'
2words = string.split() #converts string into list
3print(words[::-1])
1# Python string/number reverser
2# Kinda too much code, so don't use this, use the other examples under this answer.
3example_number = 12143
4example_string = "Hello there"
5
6def reverse(thing):
7 thing = str(thing) # convert it to a string, just in case it was a number
8 list_of_chars = [char for char in thing]
9 reversed_list_of_chars = []
10 x = -1
11
12 for char in list_of_chars:
13 reversed_list_of_chars.append(list_of_chars[x])
14 x += -1
15
16 reversed_thing = ''.join(reversed_list_of_chars)
17
18 return reversed_thing
19 # Or alternatively do:
20 print(reversed_thing)
21
22# Run it by doing this
23reverse(example_number)
24reverse(example_string)