复杂版。。。
def is_palindrome(n):
if not isinstance(n, int):
raise TypeError('Error Type Compare')
L = list(map(int, str(n)))
index = 0
flag = False
endIndex = len(L) / 2 - 1 if len(L) % 2 == 0 else (len(L) - 1) / 2 if len(L) <= 1 else (len(L) - 1) / 2 - 1
while index <= endIndex and L[index:1] == (L[-(index + 1):-index] if index > 0 else L[-(index + 1):]):
if index == endIndex:
flag = True
break
index = index + 1
return flag
忘记有[::-1]了,所以其实可以直接拿到反转后的字符串进行判断
gitKong