您需要强制转换为字符串才能反转和比较:def largest_palindrome(): # <-- arguments are not needed for y in (x for x in range(9801, 100, -1)): # use a generator, that iterates from largest to smallest. if str(y) == str(y)[::-1]: return y # early exit when largest match is found (it will be the first)print(largest_palindrome())扰流板警报:9779作为一个班轮:max([x for x in range(9801, 100, -1) if str(x) == str(x)[::-1]])作为一台班轮发电机(感谢@Austin的评论):next(x for x in range(9801, 100, -1) if str(x) == str(x)[::-1])