python如何判斷一個字符串是中文,還是英文。


參考鏈接:
https://blog.csdn.net/hit0803107/article/details/52885702

 

 

decode:  將其它編碼轉成  ===》unicode

encode:  將 unicode   ====》其它編碼

 

 

 

#-*- coding:utf-8 -*-
#python 判斷字符串是中文還是英文,只要有一個中文就算中文。


import sys
reload(sys)
sys.setdefaultencoding('utf8')

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

if __name__ == "__main__":
print check_contain_chinese('i love yiu ')
print check_contain_chinese('i love you')
print check_contain_chinese('xx中國')


 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM