python判断字符串是会否包含中文
这个方法输出结果是正确的
def is_Chinese(text): zhPattern = re.compile(u'[\u4e00-\u9fa5]+') for ch in text: match = zhPattern.search(ch) if(match): return True return False text = "中文" text = text.decode('utf-8') if(is_Chinese(text)): print("有中文")
这个方法输出结果不对
def is_Chinese(word): for ch in word: if '\u4e00' <= ch <= '\u9fff': return True return False text = "中文" text = text.decode('utf-8') print(is_Chinese(text))