Skip to content

Exercise: String Reversal

Leer en Español | Solve Online

Background/Motivation

Reversing a string is a common operation that can be accomplished in various ways, such as using loops or Python's built-in slicing capabilities. This exercise helps in understanding string manipulation and immutability.

The Task

Implement a function string_reversal(s: str) -> str that reverses a given string.

Specifications

  • Function Name: string_reversal
  • Arguments: s (str)
  • Return Type: str
  • Expected Output: The reversed string.

Constraints

  • The input string can be empty or contain any characters.

Example

>>> string_reversal("hello")
"olleh"
>>> string_reversal("Python")
"nohtyP"

Instructions

  1. Open exercises/string_reversal/solution.py.
  2. Implement the string_reversal function.
  3. Change SUBMIT = False to SUBMIT = True at the top of the file when you are ready to be graded.
  4. Run python solution.py locally to verify your solution with the built-in self-tests.