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.
🌐
W3Schools
w3schools.com › python › ref_func_reversed.asp
Python reversed() Function
The reversed() function returns a reversed iterator object. ... The iter() function returns an iterator object. The list.reverse() method reverses a List. ... If you want to use W3Schools services as an educational institution, team or enterprise, ...
Discussions

How do I reverse a string in Python? - Stack Overflow
There is no built in reverse method for Python's str object. How can I reverse a string? More on stackoverflow.com
🌐 stackoverflow.com
What is the application/function of reversed string in real life?
The only time I've ever done it professionally is when I wanted to sort a list of email addresses (or web domains) into groups of orders. I.e., I wanted to send 1000 emails at a time, but I'd prefer if all the email going to AOL went in one batch, since the connection to AOL.com would already be open. So, sorting a list where the final characters are the most significant characters. Otherwise, I haven't actually had to do it in 40 years of professional business programming. Doing it used to take somewhat more thinking than it does now, so it's probably a left-over problem from languages like C where strings aren't built in. Sort of like "how do you remove duplicates from a list?" Well, stick them as keys in a map, stupid, and move to a language with maps built in. More on reddit.com
🌐 r/AskComputerScience
10
1
December 1, 2020
What's the best way to reverse a string in Python?
Dunno about best, but using string splicing is an easy way to do it. s=s[::-1] It works by doing [start:end:step] - by leaving begin and end off and specifying a step of -1, it reverses a string More on reddit.com
🌐 r/Python
17
4
January 9, 2018
6 different ways to reverse a string in Python
Just a point of nit - don't call a variable str, it's a very bad example especially to post in a guide online. If you want people to definitely know it's a string use type hints. More on reddit.com
🌐 r/Python
6
0
March 3, 2023
People also ask

How to reverse a string in Python without a reverse function?
You can reverse a string in Python using slicing: reversed_string = original_string[::-1].
🌐
guvi.in
guvi.in › blog › python › python reverse string: 7 effective ways with examples
Python Reverse String: 7 Effective Ways with Examples
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
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.

🌐
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.
🌐
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
Find elsewhere
🌐
Career Karma
careerkarma.com › blog › python › python reverse string: a step-by-step guide
Python Reverse String: A Step-By-Step Guide | Career Karma
December 1, 2023 - Using the reversed() function to ... methods. When you’re slicing a Python string, you can use the [::-1] slicing sequence to create a reversed copy of the string....
🌐
Educative
educative.io › answers › how-do-you-reverse-a-string-in-python
How do you reverse a string in Python?
In Python, strings are ordered sequences of character data. There is no built-in method to reverse a string.
🌐
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 built-in functions to perform the task efficiently.
🌐
wikiHow
wikihow.tech › computers and electronics › software › programming › python › 6 ways to reverse a string in python: easy guide + examples
6 Ways to Reverse a String in Python: Easy Guide + Examples
March 20, 2023 - There are several easy ways to do so! You can use the slice function to reverse the string in 1 line of code. Alternatively, use a For loop or the reversed() function for additional flexibility in the reversal process.
🌐
Python Guides
pythonguides.com › python-program-to-reverse-a-string
How To Reverse A String In Python?
January 12, 2026 - Using the reversed() function is a clear and flexible way to reverse a string without slicing, especially when you want to understand how iteration works in Python.
🌐
BeginnersBook
beginnersbook.com › 2018 › 06 › python-program-reverse-string
Python Program to Reverse a given String
Here we have defined a function and in the function we are reversing a string using for loop. The steps are as follows: Step 1: Create a loop to read each character of the String one by one. Step 2: Declare an empty String. Step 3: Concatenate the read character at the beginning of the string.
🌐
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 - You can reverse a string in Python using a for loop with the following steps- Initialize an empty string to store the reversed version. Initiate a loop for iteration on string characters, i.e., characters of the initial string in reverse order ...
🌐
Javatpoint
javatpoint.com › how-to-reverse-a-string-in-python
How to reverse a string in Python - Javatpoint
How to reverse a string in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, basics, data types, operators, etc.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › how to reverse a string in python: the definitive guide
How to Reverse a String in Python: The Definitive Guide
August 25, 2025 - This method is often considered more readable by some developers because it uses explicit function names. Python my_string = "hello" reversed_string = "".join(reversed(my_string)) print(reversed_string) # Output: "olleh"
🌐
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 ... # looping through the string for char in string: # reversing the string reversed_string = char + reversed_string # returning a reversed string return reversed_string # the string to reverse ...
🌐
Jeremy Morgan
jeremymorgan.com › python › how-to-reverse-a-string-in-python
How to Reverse a String in Python: A Complete guide
December 15, 2023 - If you have byte arrays (bytearray) as inputs, you need to ensure they are converted to str() before applying slicing. Python provides the reversed() function for iterating over an object in reverse order.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-reverse-string
Python Reverse String - 5 Ways and the Best One | DigitalOcean
August 3, 2022 - However, there are various ways to reverse a string in Python. ... Using Slicing to create a reverse copy of the string. Using for loop and appending characters in reverse order · Using while loop to iterate string characters in reverse order and append them · Using string join() function ...
🌐
Linode
linode.com › docs › guides › how-to-reverse-a-string-in-python
How to Reverse a String in Python | Linode Docs
May 13, 2022 - Each instance of the function is also stores the first character of its input to add to the end of the new string. The first few recursions for the example string look as follows: example_string = "doom wolf" reverse_by_recursion("oom wolf") + "d" reverse_by_recursion("om wolf") + "o" reverse_by_recursion("m wolf") + "o" reverse_by_recursion(" wolf") + "m"