Write a Python function to reverse a string.
1Times asked
Jul 2026Last seen
Jul 2026First seen
💡 Model Answer
You can reverse a string in Python using slicing, the reversed() function, or a loop. Here’s a simple implementation using slicing:
python
def reverse_string(s: str) -> str:
return s[::-1]This returns a new string that is the reverse of the input. For example, reverse_string('hello') returns 'olleh'. The slicing method is concise and runs in O(n) time, where n is the length of the string.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500