How to check for palindrome using Python logic

The Solution to How to check for palindrome using Python logic is


A pythonic way to determine if a given value is a palindrome:

str(n) == str(n)[::-1]

Explanation:

  • We're checking if the string representation of n equals the inverted string representation of n
  • The [::-1] slice takes care of inverting the string
  • After that, we compare for equality using ==

~ Answered on 2013-06-26 22:08:00


Most Viewed Questions: