python-检查是否为中文字符串

【目标需求】

查看某一个字符串是否为中文字符串

【解决办法】

def check_contain_chinese(check_str):
    for ch in check_str:
        if u'\u4e00' <= ch <= u'\u9fff':
            return True     
        else:
            return False

【举例检验】

check_contain_chinese('abcc')
False
check_contain_chinese('123')
False
check_contain_chinese('中文')
True 

问题解决!

(仅供个人学习,不负责任,嘻嘻~~)

猜你喜欢

转载自blog.csdn.net/august1226/article/details/80626396