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

下面的程序可以判断python字符串中包不包含汉字:
# -*- coding:utf-8 -*-
import re
def  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))


 
 

你可能感兴趣的:(python 中如何判断一个字符串中包不包含汉字)