判断某个字符是否为中文

来源地址:http://snipperize.todayclose.com/snippet/py/%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E4%B8%AD%E6%96%87%E5%AD%97%E7%AC%A6--4021/

 
  
  1. """ 
  2. 判断unicode码是否为中文字符. 
  3. """ 
  4. def is_cn_char(i): 
  5.     return 0x4e00<=ord(i)<0x9fa6 
  6.  
  7. def is_cn_or_en(i): 
  8.     o = ord(i) 
  9.     return o<128 or 0x4e00<=o<0x9fa6