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
nequals the inverted string representation ofn - The
[::-1]slice takes care of inverting the string - After that, we compare for equality using
==