Checking a Number for Palindromic Behavior

Guyon Morée guyon.moree at gmail.com
Mon Oct 19 19:26:57 EDT 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