Python: how to check if a number is palindrome

Python: how to check if a number is palindrome

In this article we will see the simplest solution to check if a number is palindrome in Python.

In this article we will see the simplest solution to check if a number is palindrome in Python.

We essentially need to transform the number into a string and compare that string to its reversed version. If the two strings are equal, the number is palindrome.

def is_palindrome(num):
    s = str(num)
    rev = ''.join(reversed(s))
    return s == rev