From the course: Learning Python

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Solution: Palindromes

Solution: Palindromes - Python Tutorial

From the course: Learning Python

Solution: Palindromes

- [Instructor] All right, let's take a look at my code for this challenge. And remember, it's okay if my code is different from yours. There's usually multiple ways to solve programming problems. In order to determine whether a string is a palindrome we have to ignore capitalization and we have to get rid of spaces and punctuation. So my code starts by converting the incoming string to lowercase so that way we don't have to worry about comparing different letter casing. Next, I strip off the spaces and the punctuation from the test string. So I create a new string and then I have a for loop that checks each character in the test string. And I'm using the isalnum function which is a built-in function for Python string objects. This function checks to see if a character is alphanumeric, and if it is then I add it to my new string, otherwise I skip over it. So when this loop completes I now have a string that is all lowercase…

Contents