Palindrome Program – multiple Python solutions
A palindrome is one such string related python problem that almost all the computer science student try to solve in order to learn how python strings work. A palindrome is a string that reads the same forwards and backward.
A very simple solution for checking palindrome using python string indexing method
word=input("Please enter a word") revs=wrd[::-1] if word == revs: print("This word is a palindrome") else: print("This word is not a palindrome")
The old fashioned way we can do it like this using for loop
# Python program to check whether the entered string is palindrome or not. # program by : rakesh kumar # website : https://cbsetoday.com word = input('Enter any word :') l = len(word) found =0 for i in range(0,l//2): if(word[i]!=word[l-1-i]): found=1 if(found ==1): print("not a palindrom") else: print("Its a palindrome")
The output of the above codes are as follows
as@DESKTOP-P84OH09 MINGW64 ~/desktop $ c:/python37/python.exe c:/Users/as/Desktop/palindrome.py Enter any word :rakesh not a palindrom as@DESKTOP-P84OH09 MINGW64 ~/desktop $ c:/python37/python.exe c:/Users/as/Desktop/palindrome.py Enter any word :nitin Its a palindrome
Do you have more solutions to this problem? Please send us your solution and we would love to add that solution in this article.