Checking a Number for Palindromic Behavior

Guyon Morée guyon.moree at gmail.com
Tue Oct 20 01:26:57 CEST 2009


> >def is_palidrome (n):
> >    return str(n) == ''.join (reversed (str(n)))
>
> >which will return True if integer n is a palidromic or False
> >otherwise.
>
> I wouldn't normally provide a direct solution to this type of request; but
> since you have, may I suggest:
>
> def is_palindrome (n):
>     return str(n) == str(n)[::-1]


http://gumuz.nl/weblog/python-trick-sequence-reversal/



More information about the Python-list mailing list