BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

Python program to reverse a String using Recursion

Last Updated: June 6, 2018 by Chaitanya Singh | Filed Under: Python Examples

In the last tutorial we learned how to reverse a string in Python using loop. In this tutorial we will see how to reverse a string using recursion.

Program to Reverse String using Recursion

# Program published on https://beginnersbook.com
# Python program to reverse a given String
# Using Recursion

# user-defined recursive function
def reverse(str):
    if len(str) == 0:
        return str
    else:
        return reverse(str[1:]) + str[0]


mystr = "BeginnersBook"

print("The Given String  is: ", mystr)

print("Reversed String is: ", reverse(mystr))

Output:

The Given String  is:  BeginnersBook
Reversed String is:  kooBsrennigeB

Source code in PyCharm IDE:
Python Reverse String using Recursion

Related Python Examples:

  1. Python Program to reverse a String using loop
  2. Python program to check alphabet
  3. Python program to check even or odd number
  4. Python program to print hello World

Top Related Articles:

  1. Python Program to Check if a Number is Positive Negative or Zero
  2. Python Program to Reverse a given String
  3. Python Program to Find ASCII Value of a Character
  4. Python Program to Convert Celsius To Fahrenheit and Vice Versa
  5. Python Program to Print Calendar

About the Author

I have 15 years of experience in the IT industry, working with renowned multinational corporations. Additionally, I have dedicated over a decade to teaching, allowing me to refine my skills in delivering information in a simple and easily understandable manner.

– Chaitanya

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2012 – 2025 BeginnersBook . Privacy Policy . Sitemap