How to reverse a string in Python?
Is there any function like reverse()
to reverse a string?
1 Answer
4 years ago by Divya
reverse()
function works for lists, not for strings. So, if you want to apply that method you need to convert the string to a list. Instead of doing so, you can use string slicing to reverse a string.
s="hey"
print(s[::-1])
4 years ago by Divya