Best way to Reverse a Python string

How to Reverse a String in Python programming language?

Best way to Reverse a Python string

The Python string-slicing method is the fastest and easiest way to reverse a string. [::-1].

string[::-1] #[strat:stop:step] Just define -1 to the step
name = "DevBabu"
print(name[::-1])
ubaBveD

You can wrap this code inside a function like the following –

def reverseString(string:str):
    return string[::-1]

myText = reverseString("Hello World")
print(myText)
dlroW olleH