回数是指从左到右读和从右到左读都是一样的数,请利用filter()滤掉非回数(打印出1000内所有回数)
def is_palindrome(n):
return str(n)==str(n)[::-1] # str(n)[::-1]代表字符串从后往前读,也代表字符串的翻转
output = filter(is_palindrome,range(1,1001))
print(list(output))
回数是指从左到右读和从右到左读都是一样的数,请利用filter()滤掉非回数(打印出1000内所有回数)
def is_palindrome(n):
return str(n)==str(n)[::-1] # str(n)[::-1]代表字符串从后往前读,也代表字符串的翻转
output = filter(is_palindrome,range(1,1001))
print(list(output))
转载于:https://www.cnblogs.com/laosun0204/p/8676525.html