function to reverse a string

Python July 27, 2025 python

Function to reverse a string

python
def reverse_string(s):
    reversed_str = ''
    for char in s:
        reversed_str = char + reversed_str  # prepend each character
    return reversed_str