方法yi str ="上海自来水,水来自海上" print( str[::-1]) if str == str[::-1]: print('YES') else: print("node")
定义方法输入
s =input("输入反转值:").strip() s_list= [] for i in s: if i.isalnum(): s_list.append(i) new_s =''.join(s_list).lower() if new_s==new_s[::-1]: print("yes") else: print("no")