Interview Question

Reverse a string

Use text[::-1] for a simple code-point string reversal.

💡 Concept ✅ Quick Revision 🐍 Python

Answer

Reverse a string by creating a slice with a step of -1. • Slicing works with Python strings because they are sequences. • The result is a new string. • This reverses code points, not user-perceived grapheme clusters.

💡 Simple Example

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

Output

nohtyP

⚡ Quick Revision

Use text[::-1] for a simple code-point string reversal.