how to reverse a sting in python code example
Example 1: python reverse string
'String'[::-1] #-> 'gnirtS'
Example 2: python reverse a string
#linear
def reverse(s):
str = ""
for i in s:
str = i + str
return str
#splicing
'hello world'[::-1]
Example 3: reverse the words in a string python
string = 'hello people of india'
words = string.split() #converts string into list
print(words[::-1])