判断字符串全是中文
# Python3
def is_all_chinese(chars: str) -> bool:
'''判断字符串是否全为中文
>>> is_all_chinese('这是中文')
True
>>> is_all_chinese('这不全是中文aaa')
False
>>> is_all_chinese('aaa')
False
>>> is_all_chinese('1')
False
'''
return all('\u4e00' <= c <= '\u9fa5' for c in chars)
判断字符串包含中文
# Python3
def contains_chinese(chars: str) -> bool:
'''判断字符串是否含有中文
>>> contains_chinese('这是中文')
True
>>> contains_chinese('这不全是中文aaa')
True
>>> contains_chinese('aaa')
False
>>> contains_chinese('1')
False
'''
return any('\u4e00' <= c <= '\u9fa5' for c in chars)