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
1str="Python" # initial string
2stringlength=len(str) # calculate length of the list
3slicedString=str[stringlength::-1] # slicing
4print (slicedString) # print the reversed string
1#linear
2
3def reverse(s):
4 str = ""
5 for i in s:
6 str = i + str
7 return str
8
9#splicing
10'hello world'[::-1]
1str1="Hello"
2#if u want to take length input from user then use the next line
3#n=int(input("enter the no of elements: ")) #this one
4
5#if u don't wanna ask user the length then directly use this next line
6n=len(str1)
7
8for i in range(-1,-(n+1),-1):
9 print(str1[i],end='')
10#prints olleh
11