Solution Review: Check for a Palindrome
This review provides a detailed analysis of the solution to check whether or not a string is a palindrome.
We'll cover the following...
Solution: Using Recursion
Press + to interact
def isPalindrome(testVariable) :# Base Caseif len(testVariable) <= 1 : # Strings that have length 1 or 0 are palindromereturn True# Recursive Caselength = len(testVariable)if testVariable[0] == testVariable[length - 1] : # compare the first and last elementsreturn isPalindrome(testVariable[1: length - 1])return False# Driver Codeprint(isPalindrome("madam"))
...
Access this course and 1400+ top-rated courses and projects.