How to reverse a string in python
In this video you will learn two methods about how to reverse a string using a string slicing and another method using a for loop. Try to run the programs by yourself and comment down below if you have any queries.
Code for Method 1 : Using string Slicing
=====================================
data = input("Enter a string : ")
print("Reverse of a string is : ", data[::-1])
Code for Method 2 : Using For Loop Add Letter to Front of Reverse String
=====================================
data = input("Enter a string : ")
info = ""
for letter in data:
info = letter + info
print("Reverse of String is : ", info)
Conclusion: Try to run the above programs by yourself and comment down below if you have any queries
0 Comments