Using slicing:

>>> 'hello world'[::-1]
'dlrow olleh'

Slice notation takes the form [start:stop:step]. In this case, we omit the start and stop positions since we want the whole string. We also use step = -1, which means, "repeatedly step from right to left by 1 character".

Answer from Paolo Bergantino on Stack Overflow
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_howto_reverse_string.asp
How to reverse a String in Python
There is no built-in function to reverse a String in Python. The fastest (and easiest?) way is to use a slice that steps backwards, -1.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-do-you-reverse-a-string-in-python
How do you reverse a string in Python?
This technique reverses a string using reverse iteration with the reversed() built-in function to cycle through the elements in the string in reverse order and then use .join() method to merge all of the characters ...
People also ask

Can you use reverse on a string in Python
divPython provides a builtin function called reversed which can be used to reverse the characters in a stringdiv
๐ŸŒ
scholarhat.com
scholarhat.com โ€บ home
How to Reverse a String in Python
What is the fastest way to reverse a string in Python
divSlicing is the fastest and most efficient technique for python reverse string It uses a slice that takes a backward step 1div
๐ŸŒ
scholarhat.com
scholarhat.com โ€บ home
How to Reverse a String in Python
Is there a reversed in Python
divIs there a reverse function in Python Yes the reversed function allows us to reverse the order of items in a sequencenbspdiv
๐ŸŒ
scholarhat.com
scholarhat.com โ€บ home
How to Reverse a String in Python
๐ŸŒ
Medium
medium.com โ€บ @khasnobis.sanjit890 โ€บ python-reverse-string-74cc521cf8ca
Python Reverse String. Today we are going to write some codeโ€ฆ | by Sanjit Khasnobis | Medium
September 10, 2023 - def reverseStr_reversed_method(inputStr): inputStrlist = list(inputStr) outputStrlist = reversed(inputStrlist) outputStr = "".join(outputStrlist) return outputStr ... Here, we have used python inbuilt framework reversed method.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ reverse-string-python-5-different-ways
How to reverse a String in Python - GeeksforGeeks
We can reverse the string by taking a step value of -1. ... Python provides a built-in function called reversed() which can be used to reverse the characters in a string.
Published ย  March 3, 2026
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ 5 methods to reverse a python string
5 methods to reverse a Python string - LogRocket Blog
June 4, 2024 - >>> def w_reverse(input_string): ... new_string = '' ... count = len(input_string) - 1 ... while count >= 0: ... new_string = new_string + input_string[count] ... count = count - 1 ... return new_string >>> w_reverse('?uoy era woH') 'How are you?' Here, we are creating a function and initializing a new variable, the same as the previous example ยท Now we take the length of the input string and subtract it by 1 because the index in Python starts from 0.
Top answer
1 of 14
3168

Using slicing:

>>> 'hello world'[::-1]
'dlrow olleh'

Slice notation takes the form [start:stop:step]. In this case, we omit the start and stop positions since we want the whole string. We also use step = -1, which means, "repeatedly step from right to left by 1 character".

2 of 14
329

What is the best way of implementing a reverse function for strings?

My own experience with this question is academic. However, if you're a pro looking for the quick answer, use a slice that steps by -1:

>>> 'a string'[::-1]
'gnirts a'

or more readably (but slower due to the method name lookups and the fact that join forms a list when given an iterator), str.join:

>>> ''.join(reversed('a string'))
'gnirts a'

or for readability and reusability, put the slice in a function

def reversed_string(a_string):
    return a_string[::-1]

and then:

>>> reversed_string('a_string')
'gnirts_a'

Longer explanation

If you're interested in the academic exposition, please keep reading.

There is no built-in reverse function in Python's str object.

Here is a couple of things about Python's strings you should know:

  1. In Python, strings are immutable. Changing a string does not modify the string. It creates a new one.

  2. Strings are sliceable. Slicing a string gives you a new string from one point in the string, backwards or forwards, to another point, by given increments. They take slice notation or a slice object in a subscript:

    string[subscript]
    

The subscript creates a slice by including a colon within the braces:

    string[start:stop:step]

To create a slice outside of the braces, you'll need to create a slice object:

    slice_obj = slice(start, stop, step)
    string[slice_obj]

A readable approach:

While ''.join(reversed('foo')) is readable, it requires calling a string method, str.join, on another called function, which can be rather relatively slow. Let's put this in a function - we'll come back to it:

def reverse_string_readable_answer(string):
    return ''.join(reversed(string))

Most performant approach:

Much faster is using a reverse slice:

'foo'[::-1]

But how can we make this more readable and understandable to someone less familiar with slices or the intent of the original author? Let's create a slice object outside of the subscript notation, give it a descriptive name, and pass it to the subscript notation.

start = stop = None
step = -1
reverse_slice = slice(start, stop, step)
'foo'[reverse_slice]

Implement as Function

To actually implement this as a function, I think it is semantically clear enough to simply use a descriptive name:

def reversed_string(a_string):
    return a_string[::-1]

And usage is simply:

reversed_string('foo')

What your teacher probably wants:

If you have an instructor, they probably want you to start with an empty string, and build up a new string from the old one. You can do this with pure syntax and literals using a while loop:

def reverse_a_string_slowly(a_string):
    new_string = ''
    index = len(a_string)
    while index:
        index -= 1                    # index = index - 1
        new_string += a_string[index] # new_string = new_string + character
    return new_string

This is theoretically bad because, remember, strings are immutable - so every time where it looks like you're appending a character onto your new_string, it's theoretically creating a new string every time! However, CPython knows how to optimize this in certain cases, of which this trivial case is one.

Best Practice

Theoretically better is to collect your substrings in a list, and join them later:

def reverse_a_string_more_slowly(a_string):
    new_strings = []
    index = len(a_string)
    while index:
        index -= 1                       
        new_strings.append(a_string[index])
    return ''.join(new_strings)

However, as we will see in the timings below for CPython, this actually takes longer, because CPython can optimize the string concatenation.

Timings

Here are the timings:

>>> a_string = 'amanaplanacanalpanama' * 10
>>> min(timeit.repeat(lambda: reverse_string_readable_answer(a_string)))
10.38789987564087
>>> min(timeit.repeat(lambda: reversed_string(a_string)))
0.6622700691223145
>>> min(timeit.repeat(lambda: reverse_a_string_slowly(a_string)))
25.756799936294556
>>> min(timeit.repeat(lambda: reverse_a_string_more_slowly(a_string)))
38.73570013046265

CPython optimizes string concatenation, whereas other implementations may not:

... do not rely on CPython's efficient implementation of in-place string concatenation for statements in the form a += b or a = a + b . This optimization is fragile even in CPython (it only works for some types) and isn't present at all in implementations that don't use refcounting. In performance sensitive parts of the library, the ''.join() form should be used instead. This will ensure that concatenation occurs in linear time across various implementations.

๐ŸŒ
Real Python
realpython.com โ€บ reverse-string-python
Reverse Strings in Python: reversed(), Slicing, and More โ€“ Real Python
July 31, 2023 - These features allow you to use slicing to directly generate a copy of a given string in reverse order. The second option is to use the built-in function reversed() to create an iterator that yields the characters of an input string in reverse order.
Find elsewhere
๐ŸŒ
ScholarHat
scholarhat.com โ€บ home
How to Reverse a String in Python
September 11, 2025 - Using a Loop: Iterates through the string and prepends characters to build the reversed string ยท Using reversed() Function: Converts the string into an iterator and joins the reversed characters.
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ how to reverse a string in python in 10 ways! (code)
How To Reverse A String In Python In 10 Ways! (Code)
December 21, 2023 - In this section, we will discuss how to use the reversed() function to reverse a Python string. This inbuilt function can reverse any iterable object, including strings. But since strings in Python are immutable, we use this function indirectly.
๐ŸŒ
GUVI
guvi.in โ€บ blog โ€บ python โ€บ python reverse string: 7 effective ways with examples
Python Reverse String: 7 Effective Ways with Examples
January 8, 2026 - In this example, the reverse_string function takes an input string, applies the reversed() function to create an iterator, and then uses "".join() to form the reversed string. This method is straightforward and leverages Pythonโ€™s powerful ...
๐ŸŒ
Guru99
guru99.com โ€บ home โ€บ python โ€บ how to reverse a string in python (5 methods)
How to reverse a String in Python (5 Methods)
3 weeks ago - The first method for reversing strings is using a for loop as in the code snippet below: ... # function for reversing a string def reverse_string(string): # an empty string for storing reversed string reversed_string = "" # looping through the ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
Reverse a String in Python in 3 Ways #Shorts - YouTube
Reverse a String in Python in 3 Ways #ShortsPython string doesn't have a built-in reverse() function. Instead, there are multiple ways to reverse a string in...
Published ย  August 2, 2021
๐ŸŒ
Exercism
exercism.org โ€บ tracks โ€บ python โ€บ exercises โ€บ reverse-string โ€บ approaches โ€บ built-in-list-reverse
Explore the 'Use the built-in list.reverse() function' approach for Reverse String in Python on Exercism
February 15, 2025 - Explore the 'Use the built-in list.reverse() function' approach for Reverse String in Python on Exercism. Create a list of codepoints, use list.reverse() to reverse in place, and join() to make a new string.
๐ŸŒ
dbader.org
dbader.org โ€บ blog โ€บ python-reverse-string
How to Reverse a String in Python โ€“ dbader.org
January 9, 2018 - This works well, however it is slightly arcane and therefore not very Pythonic, in my opinion. ... The built-in reversed() function allows you to create a reverse iterator for a Python string (or any sequence object.)
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ 5 ways to reverse a string in python
How to Reverse a String in Python in 5 Ways | Reverse Function
February 5, 2025 - This code uses the reversed() function to create a reverse iterator over the characters in the string, and then joins the characters together using the join() function calls. We can also use list comprehension to reverse a string.
๐ŸŒ
Python Engineer
python-engineer.com โ€บ posts โ€บ reverse-string-python
How to reverse a String in Python - Python Engineer
There is no built-in string.reverse() function. However, there is another easy solution. ... The recommended way is to use slicing.
๐ŸŒ
24HourAnswers
24houranswers.com โ€บ technical-tutoring-tips โ€บ How-to-Reverse-a-String-in-Python
How to Reverse a String in Python
October 13, 2021 - In Python, strings are iterable and there is no included function to reverse a string. One rationale for excluding a string.reverse() method is to give Python developers an incentive to leverage the power of this special circumstance.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ string reverse in python
Reverse String in Python - Scaler Topics
April 8, 2022 - We don't have any inbuilt function for reversing the string. So we follow different approaches for string reversal as listed below: ... Let's take a look at all these methods to reverse a string.