beginnersbook.com

  • Home
  • All Tutorials
    • Learn Servlet
    • Learn JSP
    • Learn JSTL
    • Learn C
    • Learn C++
    • Learn MongoDB
    • Learn XML
    • Learn Python
    • Learn Perl
    • Learn Kotlin
    • Learn jQuery
  • Core Java
  • OOPs
  • Collections
  • Java I/O
  • JSON
  • DBMS

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

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

Recently Added..

  • JSON Tutorial
  • Java Regular Expressions Tutorial
  • Java Enum Tutorial
  • Java Annotations Tutorial

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap