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

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

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 *

Python Tutorial

Introduction

  • Python Tutorial
  • Python Introduction
  • Install Python
  • PyCharm IDE Installation
  • Python in PyCharm
  • Python Comments
  • Python Variables
  • Python Keywords & Identifiers
  • Python data types

Flow Control

  • Python If
  • Python if..else
  • Python if..elif..else
  • Python Nested If
  • Python for loop
  • Python while loop
  • Python break
  • Python continue
  • Python pass

Python Functions

  • Python Functions
  • Python Recursion

Python Datatypes

  • Python Numbers
  • Python List
  • Python Strings
  • Python Tuple
  • Python Dictionary
  • Python Set

Python OOPs

  • Python OOP
  • Python Class & Object
  • Python Constructors

Python Examples

  • Python Programs

Copyright © 2012 – 2023 BeginnersBook . Privacy Policy . Sitemap