def is_palindrome(n): s = str(n) count = 0 if len(s) > 1: for n in range(int(len(s) / 2)): if s[n] != s[-1 - n]: count = count + 1 return not count else: return True
判断语句里有filter,就不用自己写生成器了
def is_palindrome(n): s = str(n) return s[::] == s[::-1]
切片
def is_palindrome(n): s = str(n) count = 0 for n in range(int(len(s) / 2)): if s[n] != s[-1 - n]: count = count + 1 return not count
发现并不需要判断一位数
Sign in to make a reply
南小i
判断语句里有filter,就不用自己写生成器了