Discuss / Python / is_palindrome

is_palindrome

Topic source

Pooki201

#1 Created at ... [Delete] [Delete and Lock User]

def is_palindrome(n):

    s = str(n)

    l = len(s)

    if l == 1:

        return True

    mid = (l - 1)//2

    if l % 2 == 0:

        return s[0:mid+1] == s[mid+1:l]

    else:

        return s[0:mid] == s[mid+1:l]


  • 1

Reply