reverse a string in python without using any built in function

Jeevachaithanyan Sivanandan - Dec 14 '23 - - Dev Community

If you get an interview question to reverse a string without using any python built in method, try below

def reverse_text(text):
    reversed_text = ""
    length = len(text)

    for i in range(length - 1, -1, -1):
        reversed_text += text[i]

    print(f"Reversed text: {reversed_text}")

# Example usage:
text = "hello welcome to the python world"
reverse_text(text)
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player