store one string to another string in python by R4R Team

we have store the one string into another string in reverse order like an example -
then it reverse in other string is

program -

print("Enter the string")
print("Input string is -"+s)

#first way
for i in range(l):
print("string after reverse by first method is - "+s1)

#second way
print("string after reverse by second method is -"+s1)

output -

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].
Leave a Comment:
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!