python 中如何判断一个字符串中包不包含汉字

来源:互联网 发布:改革开放40年成就数据 编辑:程序博客网 时间:2024/06/06 01:52
下面的程序可以判断python字符串中包不包含汉字:
<pre name="code" class="python"># -*- coding:utf-8 -*-import redef  has_hz(contents):      Pattern = re.compile(u'[\u4e00-\u9fa5]+')        match = Pattern.search(contents)    if match:        return u'包含中文'     else:        return u'不包含中文'  if __name__ == "__main__":    contents= 'hanzi'    print(has_hz(contents))


                                             
0 0