def is_all_chinese(strs): #去掉换行符 strs=strs.replace(" ","") for _char in strs: if not 'u4e00' <= _char <= 'u9fa5': print("不是汉字") return False print("是汉字") return True
测试
line="刘文华" is_all_chinese(line)
是汉字True