By using for loop we can reverse a sting. The function len() will return the length of the string. Using the length of the string we can start from the last position char and come upto the first char.
n=len(str) # length of the string
for i in range(n-1,-1,-1):
By using string slice
This is the shortest code to reverse a string. ( watch the last line only )
The first position of a string is 0 and last position is -1. The last line in below code will reverse the string as we are asking for full string starting from last (right most ) position.
print(str[:2]) # first two chars from left # pl
print(str[:-2]) # except last two chars # plus2n
print(str[-1]) # last position # t
print(str[::]) # full string starting from left # plus2net
print(str[::-1]) # from last position full string # ten2sulp