法1
def is_huiwen(x):
return x[::] == x[::-1]
法2
def is_huiwen(x):
t = len(x) // 2
if x[:t] == x[:(len(x)-1) -t :-1]: #找对称轴
return True
else:
return False
print(is_huiwen("1221"))
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com