Discuss / Python / is_palindrome

is_palindrome

Topic source

在路上Ce

#1 Created at ... [Delete] [Delete and Lock User]
# do like this:
def is_palindrome(num):
    snum = str(num)
    i = 0   
    while i < len(snum) - 1 - i:
        if snum[i] != snum[len(snum) - 1 - i]:
            return False        
        i += 1   
    return True

#or below
def is_palindrome_simple(num):
    snum = str(num)
    return snum == snum[::-1]


  • 1

Reply