Check Palindrome String

Check if string is palindrome.

Logic BuildingBeginner
Logic Building
# Take string input
s = input("Enter a string: ")

# Check palindrome
if s == s[::-1]:
    print("Palindrome")
else:
    print("Not a palindrome")

Output

Enter a string: racecar
Palindrome

Enter a string: hello
Not a palindrome

Compare string with its reverse.

Key Concepts:

  • Reverse string using slicing
  • Compare with original
  • If equal, palindrome