py 判断中文字符串

1.编码范围

https://blog.csdn.net/mouday/article/details/81512870

import sys

def check_contain_chinese(check_str):
    for ch in check_str.encode('utf-8').decode('utf-8'):
        if u'\u4e00' <= ch <= u'\u9fff':
            return True
    return False

print(check_contain_chinese('i love yiu '))
print(check_contain_chinese('i love you'))
print(check_contain_chinese('()'))

很多博客都是这么写的,但是它并不能判断中文符号。

 像上面中文的括号,就不在上述范围内。

posted @ 2020-09-19 15:03  lypbendlf  阅读(223)  评论(0编辑  收藏  举报