Premium Only Content
Check If A String Is A Palindrome in Python
Function Definition:
is_palindrome is a recursive function that checks whether a given string s is a palindrome.
String Conversion:
s = s.lower() converts the input string to lowercase. This ensures case-insensitive comparison.
Base Case:
The base case checks if the length of the modified string s is 1 or less.
If true, it means the string is a palindrome (or an empty string), and the function returns True.
Recursive Case:
If the length of the string is greater than 1, it checks if the first and last characters of the string are equal (s[0] == s[-1]).
If true, it calls itself recursively with the substring excluding the first and last characters (is_palindrome(s[1:-1])).
Returning Results:
If any recursive call or the base case returns False, the function returns False.
If all recursive calls and the base case return True, the function returns True.
Example:
The code then applies the is_palindrome function to the string "radar".
The result is printed, indicating whether "radar" is a palindrome.
Output:
Running this code will output True, indicating that "radar" is indeed a palindrome.
This function efficiently checks for palindromes in a case-insensitive manner, making it suitable for various scenarios where case sensitivity is not required.
-
24:55
Jasmin Laine
1 day agoCarney BRAGS About ‘Investment’—Poilievre Drops a FACT That Stops the Room
7.06K16 -
LIVE
SIM_N_SHIFT GAMING
49 minutes agoGRAND THEFT AUTO WITH FRIENDS
24 watching -
VikingNilsen
10 hours ago🔴LIVE - VIKINGNILSEN - THE NEW PRELUDE - SOULFRAME
136 -
7:45
Colion Noir
1 day agoThey Made Glock “Unconvertible” To Please Politicians, Guess What The Internet Did?
9.31K21 -
23:42
The Kevin Trudeau Show Limitless
1 day agoThe Brotherhood’s Ancient Mirror Code Revealed
12.5K6 -
11:21
Degenerate Jay
1 day ago $6.96 earnedSilent Hill's New Movie Could Be A Bad Idea...
19.9K3 -
3:19:35
The Nunn Report - w/ Dan Nunn
5 hours ago[Ep 801] Dems Setup & Disgusting Response to DC Tragedy | Giving Thanks With Rush
13.1K9 -
20:23
Neil McCoy-Ward
7 hours ago🚨 She Wasn’t Ready for This (TOTAL PUBLIC HUMILIATION!)
28.5K18 -
18:46
ThinkStory
1 day agoIT: WELCOME TO DERRY Episode 5 Breakdown, Theories, & Details You Missed!
28.9K -
2:23:05
Badlands Media
15 hours agoBadlands Daily – Nov. 27, 2025
132K41