DEV Community

Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on • Edited on

reverse a string in python without using any built in function

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

Top comments (0)