判断的方法如下:
def palindrome(arg):
s = str(arg)
length = len(s)
middle = length // 2
left = s[:middle]
right = s[middle + 1:][::-1] if length / 2 > middle else s[middle:][::-1]
return right == left
输出示例:
print(palindrome(123)) # False
print(palindrome(123321)) # True
print(palindrome(1234321)) # True
print(palindrome("abc")) # False
print(palindrome("abccba")) # True
print(palindrome("abcdcba")) # True