Palindrome String Program in Python
Here you will get the example code to check palindrome string program in python programming.
A string that can be read equally forwards and backwards is called a palindrome string.
Example code to Check Palindrome String Program in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #Palindrome string program # Enter a string string = input("Enter a string: ") # Remove spaces and convert string to lowercase string = string.replace(" ", "").lower() is_palindrome = True # Check if string is palindrome using for loop for i in range(len(string) // 2): if string[i] != string[len(string) - 1 - i]: is_palindrome = False break if is_palindrome: print(f"{string} is a palindrome.") else: print(f"{string} is not a palindrome.") |
Output 1 :
Enter a string: coderevise.com
coderevise.com is not a palindrome.
Output 2 :
Enter a string: madam
madam is a palindrome.
Check out our other Python examples