reverse a string in python
Code snippet on how to reverse a string in python
def reverse_string(string):
string = string[::-1]
return string
print(reverse_string('TutorialsPoint'))
This code snippet is used to reverse a string in python. First, the code defines a function ‘reverse_string’ which takes one argument ‘string’. Then, the argument is converted into a sequence of characters and reversed using slicing technique. Finally, the reversed string is returned by the function. In the end, the ‘reverse_string’ function is called with ‘TutorialsPoint’ as a string parameter, thus returning the reversed string ‘tniopSlaicirtuT’.