Discuss / Python / 交作业啦,看了大佬们的答案,发现自己写复杂了(hahaha)

交作业啦,看了大佬们的答案,发现自己写复杂了(hahaha)

Topic source
def is_palindrome(n):
	s=str(n)
	l=len(s)
	if l==1:
		return True #单位数正确
	elif l%2==0:
		return s[:l//2] == s[:l//2-1:-1] #偶数位数
	else:
		return s[:l//2] == s[:l//2:-1] #奇数位数

  • 1

Reply