Learn how to check if a word is a palindrome in Python using string slicing. The code assigns a word like "racecar" to a variable, reverses it with [::-1], and compares it to the original. If they match, it prints True.
Chapters
Let's write a Python program to check if the given string is palindrome. Palindromes are those words which are same from both the sides, which means if you are reading it from left-hand side and if you are reading it from right-hand side, if both are same, then it is a palindrome. So let's create a variable myword. I am going to store racecar in it, which is same from both the sides. If you can check it, R-A-C-E-C-A-R. So if you are reading it from the another side also, it's going to be the same. So I'm going to print it here. I am using the slicing one so that I can reverse my string and check it whether both are equal or not. If in case it is equal, it will return true, else it will return false to us. So here we got true because the race car is a palindrome word.