How to Reverse a String in Python

What you’ll build or solve

You’ll reverse a string in Python using the two standard patterns, then use that result for a simple palindrome check.

When this approach works best

This approach works best when you need to:

  • Reverse characters in a string, like turning "abc" into "cba".
  • Create a reversed version of a value for display or comparison.
  • Compare a string to its reverse, like checking a palindrome.

Avoid this approach when:

  • You need to reverse user-visible text with complex characters (some emoji and combined accents). Simple reversal can look wrong because some characters are made of multiple code points.

Prerequisites

  • Python 3 installed
  • You can run a short Python script
  • You know what a string is

Step-by-step instructions

1) Reverse a string with slicing

Use slice syntax with a step of -1.

text="Python"
reversed_text=text[::-1]
print(reversed_text)

This is the most common and shortest option.


2) Reverse a string with reversed() and join()

Use this when you prefer an explicit reverse iterator, then rebuild a string.

text="Python"
reversed_text="".join(reversed(text))
print(reversed_text)

What to look for:

reversed(text) returns an iterator, so you need "".join(...) to get a string.


3) Check if a string is a palindrome

Compare the string to its reverse.

text="level"
print(text==text[::-1])

For a case-insensitive check:

text="Level"
clean=text.lower()
print(clean==clean[::-1])

Examples you can copy

1) Reverse a string for display

label="mimo"
print(label[::-1])

2) Reverse a string and keep the original

original="ABCDE"
reversed_version=original[::-1]

print("original:",original)
print("reversed:",reversed_version)

3) Palindrome check that ignores spaces and punctuation

text="A man, a plan, a canal: Panama"
clean="".join(chforchintext.lower()ifch.isalnum())
print(clean==clean[::-1])

Common mistakes and how to fix them

Mistake 1: Trying to call a non-existent reverse() method on a string

You might write:

text="Python"
print(text.reverse())

Why it breaks:

Strings are immutable and do not have reverse(), so you get an AttributeError.

Correct approach:

text="Python"
print(text[::-1])

Mistake 2: Using reversed() without joining

You might write:

text="Python"
print(reversed(text))

Why it breaks:

reversed(text) is an iterator, not the reversed string.

Correct approach:

text="Python"
print("".join(reversed(text)))

Mistake 3: Reversing with the wrong slice

You might write:

text="Python"
print(text[-1:0:-1])

Why it breaks:

This slice skips the first character because the stop index 0 is excluded.

Correct approach:

text="Python"
print(text[::-1])

Troubleshooting

If you see AttributeError: 'str' object has no attribute 'reverse', use slicing text[::-1] or "".join(reversed(text)).

If your output looks like <reversed object at ...>, you printed the iterator. Wrap it with "".join(...).

If your palindrome check fails for mixed case or punctuation, normalize with .lower() and filter with .isalnum().

If your reversed string looks odd with certain emoji or accented characters, treat the string as user-facing text and consider a Unicode-aware approach.


Quick recap

  • Reverse a string with slicing: text[::-1].
  • Reverse with reversed() plus join: "".join(reversed(text)).
  • Check palindromes by comparing text (or a cleaned version) to its reverse.