根据编码判断字符串是中文字符串还是英文字符串

# -*- coding: utf-8 -*-
import  os
'''
判断字符串是中文还是英文
只要是字符串总含有一个中文字符,便认为是中文字符串
'''
def English_or_Chinese(check_str):
    for ch in check_str.encode('utf-8').decode('utf-8'):
        if u'\u4e00' <= ch <= u'\u9fff':
            return True
    return False
if __name__ == '__main__':
    CH_str = "你好"
    EN_str = "Hello"
    print(English_or_Chinese(CH_str))#True
    print(English_or_Chinese(EN_str))#False

  

猜你喜欢

转载自www.cnblogs.com/songdongdong6/p/10664999.html
今日推荐