we have store the one string into another string in reverse order like an example -
then it reverse in other string is
print("Enter the string")
print("Input string is -"+s)
for i in range(l):
print("string after reverse by first method is - "+s1)
print("string after reverse by second method is -"+s1)
Enter the string
Input string is -mytext
String after reverse by first method is - txetym
String after reverse by second method is - txetym
- In this program, first method use the looping concept and we traverse the given string from the backside and store in the new string so new string get the reverse of the given string, this type of concept are also possible in some other programming language like C,C++,JAVA.
- but in second method we use something like s[::-1],Generally in s[x:y:z], x and y define the starting and ending range of the string and z define the order of traversing, so in this program we use s[::-1] so here x is 0 and y is actual length and z is -1.
- Why -1 ? , because here we want to traverse our given string in reverse order so we take -1.
- If we want to copy given string in another string directly so we use simply s[::1].