Python Program to Check if Given String is Palindrome or Not using Recursion

Python Program to Check if Given String is Palindrome or Not using Recursion

Write Python Program to Check if Given String is Palindrome or Not using Recursion

# Write Python Program to Check if Given String is Palindrome or Not using Recursion

def palindrome(S):
    if len(S) < 1:
        return True
    else:
        if S[0] == S[-1]:
            return palindrome(S[1:-1])
        else:
            return False

S = 'ABBDCBA'
ans = palindrome(S)
if ans == True:
    print(f'{S} is Palindrome')
else:
    print(f'{S} is Not Palindrome')

Output:

Run 1:
ABBDCBA is Not Palindrome

Run 2:
ABCBA is Palindrome