In this challenge, you’ll write a Python function that reverses a string.
You’ll practice basic string manipulation and handling edge cases.
Estimated time: 10 minutes | Difficulty: Beginner
Problem
Write a Python function that takes a string and returns the reversed version.
Inputs
- text:
str— the input string
Output
Return the reversed string.
Examples
Example 1
Input String
"python"
Output String
"nohtyp"
Example 2
Input String
""
Output String
""
Constraints
- Do not use external libraries
- Input may be empty
Requirements
- Function name:
reverse_string(text: str) -> str
Starter Code
def reverse_string(text: str) -> str:
pass
(please click on ‘Solution’ to view the solution code)

Explanation
- Uses Python slicing to reverse the string
- Time complexity: O(n)
- Space complexity: O(n)
(please click on ‘Testing code’ to view ways to test the solution code)

You can use the following tests above to verify your solution locally.
🔗 View reference solution on GitHub
(After you’ve tried the challenge)
Nice work!
You’ve completed this challenge. The best way to improve your Python skills is to keep practicing while the concept is fresh.
👉 Next Challenge → Count Words in a Sentence
Want more practical Python challenges?
Subscribe to the Solve With Python newsletter and get new problems delivered to your inbox.