Skip to Main Content
Blog

Check Palindrome String in Python

Check Palindrome String in Python

Write a Java program that accepts a string from the user and determines whether it is a palindrome, ignoring non-alphabetic characters and case sensitivity.A palindrome is a word or phrase that reads the exact same backward as it does forward.

Output

## Example 1
Enter string: civic
Palindrome

## Example 2
Enter string: banana
Not Palindrome

## Example 3
Enter string: A man, a plan, a canal: Panama
Palindrome

Solution

def main():
	"""
	Checks if a string is a Palindrome or not.
	"""

	text = input("Enter a string: ")

	is_palindrome: bool
	for i in range(len(text) // 2):
		if text[i] != text[-(i + 1)]:
			is_palindrome = False
			break
	else:
		is_palindrome = True

	print(is_palindrome)