reverse string defination in python code example
Example 1: python reverse string
'String'[::-1]
Example 2: how to reverse a string in python
string = "racecar"
print(string[::-1])
Example 3: reverse the words in a string python
string = 'hello people of india'
words = string.split()
print(words[::-1])
Example 4: reverse a string in python
example_number = 12143
example_string = "Hello there"
def reverse(thing):
thing = str(thing)
list_of_chars = [char for char in thing]
reversed_list_of_chars = []
x = -1
for char in list_of_chars:
reversed_list_of_chars.append(list_of_chars[x])
x += -1
reversed_thing = ''.join(reversed_list_of_chars)
return reversed_thing
print(reversed_thing)
reverse(example_number)
reverse(example_string)