Simply exclude the end range index...

Copy>>> foo[3::-1]
'3210'

Ironically, about the only option I think you didn't try.

Answer from Andrew White on Stack Overflow
๐ŸŒ
Real Python
realpython.com โ€บ reverse-string-python
Reverse Strings in Python: reversed(), Slicing, and More โ€“ Real Python
July 31, 2023 - In other words, passing None to ... The second and arguably the most Pythonic approach to reversing strings is to use reversed() along with str.join()....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-reverse-slicing-of-given-string
Python - Reverse Slicing of given string - GeeksforGeeks
July 12, 2025 - Using slicing with [::-1] in Python, we can reverse a string or list. This technique works by specifying a step of -1, which starts at the end of the sequence and moves backward, effectively reversing the order of elements.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ reverse-string-python-5-different-ways
How to reverse a String in Python - GeeksforGeeks
This slicing method is one of the simplest and an efficient method to reverse a string. It is easy to remember and best suited for reverse the string quickly. ... The first colon (:) means that the entire string is being selected.
Published ย  November 21, 2024
๐ŸŒ
Reddit
reddit.com โ€บ r/python โ€บ 7 proven methods to reverse the python string in 2021
r/Python on Reddit: 7 proven methods to reverse the python string in 2021
December 4, 2021 -

How to reverse the python string now in 2021?

Hello to all python buddies,

You're stirring your cofee, and going to read r/Python. And you love the blog post.

Today, I'm going to make r/Python more lovable to you.

I'm going to show you the 6 proven methods to reverse the python string. Which are easy and quick to do.

So, start these methods

โ˜บ๏ธ

  1. Reverse the string using slice method

You can reverse the string using slice method.

The slice indicates the [start:end] position.

A start is a position where sequence start. and end is the position where sequence ends.

The first position is 0th index.

So, here you can use [::-1].

The [::-1] means sequence starting from last of the string.

For example,

a = ["hello"]

print(a[::-1])

It'll reverse the python string.

>>> olleh

2. Reversed the string using reversed() &join() methods

First of all, the reversed() method reverse the sequence.

After reversed() with you can join() every iterables as string.

Basically, the join() method join the iterables as a string seperator.

reversed() & join()

After running, this code you'll get something like

๐Ÿ‘‡

output

3. Reversed the string: join() and sorted() method

As you know, sorted() sort the string or sequences in ascending or descending method.

Here, I'm going to use descending order.

For descending order, pass reverse = True inside sorted().

And previously, I've told that join joins the sequences as a string seperator.

For example,

join() & sorted()

Here, you can see that first I've sorted the string in descending order.

After that, I've join every character as a string.

When you run above code, you'll get:--->

output

So, you've get the reversed string as output.

4. Reversed the string using for loop

You can reverse the string using for loop.

To create the reverse string in for loop, you need function with empty string.

The every new string add to the empty string.

After adding, all the string it becomes the reverse string.

For example,

code

After running code, you'll get--->

output

So, here you've seen how to reverse the python string. I've told you the 6 methods.

And here I've shown you the 4 methods.

But I'm going to show you 3 methods more.

That means 7 method for reverse the python string.

So, I've given you 1 bonus method.

To get these 3 methods, check out the

๐Ÿ‘‡

https://www.heypython.com/python-programming/reverse-the-python-string/

๐ŸŒ
Flexiple
flexiple.com โ€บ python โ€บ python-reverse-string
Reverse String In Python - Flexiple
The slice [::-1] starts from the end of the string and moves backwards, thus reversing the string. This method is straightforward, requires no additional memory allocation, and executes in linear time relative to the string's length. To reverse a string in Python, the reversed() method ...
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ how-do-you-reverse-a-string-in-python
How do you reverse a string in Python?
Three methods to reverse a string are explained below: Strings can be reversed using slicing. To reverse a string, we simply create a slice that starts with the length of the string, and ends at index 0.
Find elsewhere
๐ŸŒ
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.
Top answer
1 of 14
3161

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.

๐ŸŒ
Python Engineer
python-engineer.com โ€บ posts โ€บ reverse-string-python
How to reverse a String in Python - Python Engineer
Slicing syntax is [start:stop:step]. In this case, both start and stop are omitted, i.e., we go from start all the way to the end, with a step size of -1. As a result, the new string gets reversed.
๐ŸŒ
Bhrighu
bhrighu.in โ€บ blog โ€บ reverse-a-string-in-python
How to Reverse a String in Python (5 Easy Methods)
One of the most Pythonic and efficient ways to reverse a string in Python is using string slicing. Python allows negative step values in slices, enabling easy backward traversal of sequences.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ string-slicing-in-python
String Slicing in Python - GeeksforGeeks
s[-8:-1:2] slices the string from ... every second character. To reverse a string, use a negative step value of -1, which moves from the end of the string to the beginning....
Published ย  July 12, 2025
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ python-reverse-string
Python Reverse String - 5 Ways and the Best One | DigitalOcean
August 3, 2022 - I understand the first one is to ... colon operator tell Python to do? Thanks ... Hi, Thank you for the explanation. I also wanted to know how to add new lines to the output. For example I have made a reverse string input program: def reverse_slice(s): return s[::-1] ...
๐ŸŒ
Jeremy Morgan
jeremymorgan.com โ€บ python โ€บ how-to-reverse-a-string-in-python
How to Reverse a String in Python: A Complete guide
string = "Hello, World!" reversed_string = string[::-1] print(reversed_string) ... Readable and straightforward code. Uses Pythonโ€™s slice notation, which is easy to understand for most developers.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ python โ€บ hcwbjlmi โ€บ python-reverse-string-example
How do I reverse a string in Python?
The easiest and fastest way to reverse a string in Python is to use the slice operator [start:stop:step]. When you pass a step of -1 and omit the start and end values, the slice operator reverses the string.
๐ŸŒ
GUVI
guvi.in โ€บ blog โ€บ python โ€บ python reverse string: 7 effective ways with examples
Python Reverse String: 7 Effective Ways with Examples
June 6, 2024 - Letโ€™s explore the practical applications of reversing strings using slicing. Consider the string txt = "Hello World". To reverse it, you simply use the slice txt[::-1], which outputs "dlroW olleH".
๐ŸŒ
LogRocket
blog.logrocket.com โ€บ home โ€บ 5 methods to reverse a python string
5 methods to reverse a Python string - LogRocket Blog
June 4, 2024 - Here we assign values -1 to step and None for a start and stop index. Then, we use the slice() function, store the object into the variable slicing, and use it with the string later. In this method, we use two inbuilt functions: reversed and join.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ fastest way to reverse a string - and it's not extended string splicing?
r/learnpython on Reddit: Fastest way to reverse a string - and it's not extended string splicing?
August 12, 2020 -

An interview question I got was the following:

Write a function that reversed a string s. Speed is important.

I gave them back a 1 liner, returning

s[::-1]

I was told there's a faster method with some optimisations possible.

Some assumptions:

  • Reasonable real world memory limitations.

  • Input string is a valid string.

  • No information on distribution or makeup of strings

How should I have done it?

๐ŸŒ
C# Corner
c-sharpcorner.com โ€บ article โ€บ how-to-reverse-a-string-in-python-using-slicing
How to Reverse a String in Python Using Slicing
August 11, 2025 - Each character is placed before the existing string, building it in reverse. Less efficient for long strings. String slicing is a simple yet powerful tool in Python. By writing [::-1], you can reverse a string without loops or extra functions.