Reversing a string means creating a new string where the characters appear in the opposite order. Python strings are immutable, so every reversal method returns a new string instead of changing the original.
Tested on: Python 3.13.3; kernel 6.14.0-37-generic.
Quick answer: reverse a string in Python
Use text[::-1].
text = "hello"
print(text[::-1])This prints olleh. For most scripts, slicing is the simplest and most common way to reverse a string. Use "".join(reversed(text)) when you want to work with the reversed() iterator, but slicing is the default choice.
Python reverse string quick reference
| Task | Use |
|---|---|
| Reverse a string | text[::-1] |
| Reverse using a function | def reverse_string(text): return text[::-1] |
Reverse with reversed() |
"".join(reversed(text)) |
| Reverse using for loop | Build result by adding characters in front |
| Reverse using while loop | Read characters from last index to first |
| Reverse words, not characters | " ".join(text.split()[::-1]) |
| Check palindrome | text == text[::-1] |
| Avoid | text.reverse() because strings do not have reverse() |
Reverse string using slicing
text[::-1] is the recommended default. In slice notation text[start:stop:step], a step of -1 walks backward through the string and returns a new string.
text = "Python"
print(text[::-1])
print(text)The first print is nohtyP. The original text is unchanged.
Python sequence slicing supports s[i:j:k], where k is the step. For a negative step, omitted start and stop values use the appropriate end of the sequence. See Python substring and slicing for more slice patterns.
Reverse string using a function
Wrap slicing in a small function when you want a reusable helper.
def reverse_string(text):
return text[::-1]
print(reverse_string("hello world"))This prints dlrow olleh. Keep the function simple and use reverse_string naming instead of names like reverseFunction.
Reverse string using reversed() and join()
reversed(text) returns a reverse iterator, not a string.
text = "hello"
print(reversed(text))
print("".join(reversed(text)))The first line shows a reversed object. The second line prints olleh.
The Python docs define reversed() as returning a reverse iterator over a sequence.
string[::-1] vs reversed() with join()
| Method | Returns | Best for |
|---|---|---|
text[::-1] |
New string | Simple string reversal |
"".join(reversed(text)) |
New string | Teaching iterators or working with generic reversible sequences |
reversed(text) |
Reverse iterator | Looping over characters backward |
Reverse string using for loop
A for loop builds the reversed string by prepending each character. This is useful for learning, not the best default in production.
text = "hello"
reversed_text = ""
for char in text:
reversed_text = char + reversed_text
print(reversed_text)This prints olleh.
For large strings, repeated concatenation can be slow because strings are immutable. The Python docs note that building strings from many small pieces is better done with a list and join().
text = "hello"
chars = []
for char in text:
chars.insert(0, char)
print("".join(chars))Reverse string using while loop
A while loop reads characters from the last index down to zero.
text = "hello"
reversed_text = ""
index = len(text) - 1
while index >= 0:
reversed_text += text[index]
index -= 1
print(reversed_text)This prints olleh. Use this mainly for index-based learning; prefer text[::-1] in real code.
Reverse words in a string
Reversing characters and reversing word order are different tasks.
Character reverse:
text = "hello world"
print(text[::-1])This prints dlrow olleh.
Word order reverse:
text = "hello world"
print(" ".join(text.split()[::-1]))This prints world hello. The query “reverse string order” sometimes means word order, not character order. See Python split string for more ways to break text into words.
Reverse string and check palindrome
A palindrome reads the same forward and backward.
def is_palindrome(text):
return text == text[::-1]
print(is_palindrome("level"))
print(is_palindrome("hello"))This prints True, then False.
If spaces or letter case should be ignored, normalize first:
def is_palindrome(text):
cleaned = text.lower().replace(" ", "")
return cleaned == cleaned[::-1]
print(is_palindrome("Never odd or even"))This prints True for the normalized phrase.
Can you reverse a string in place?
No. Python strings are immutable sequences of Unicode code points, so you cannot swap characters inside the original string object.
You can convert to a list, swap characters, and join back, but that is usually unnecessary when text[::-1] already solves the task.
text = "hello"
chars = list(text)
chars.reverse()
print("".join(chars))
print(text)This prints olleh, then the unchanged original hello.
Common mistakes with reversing strings
- Calling
text.reverse()on a string - Thinking
reversed(text)returns a string - Forgetting
"".join()withreversed() - Confusing reverse characters with reverse word order
- Using
list.reverse()and expecting a string result without joining - Using
stras a variable name - Using expensive repeated concatenation on very large strings
- Naming helpers
reverseFunctioninstead ofreverse_string - Forgetting strings are immutable
- Expecting perfect visual reversal for every Unicode combining mark or emoji
- Filling a string article with repeated list-reversal examples
Summary
Use text[::-1] for most string reversal in Python. Use "".join(reversed(text)) when you want to demonstrate reversed(). For loops and while loops are mainly for learning how reversal works. Strings are immutable, so reversal always produces a new string. To compare a string with its reverse for palindrome checks, see Python compare strings.

