python根据unicode判断语言类型的示例分析

  介绍

小编给大家分享一下python根据unicode判断语言类型的示例分析,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!

具体如下。

实例代码:

def  is_chinese (uchar):,   “““判断一个unicode是否是汉字“““,   if 才能;uchar 祝辞=,u # 39; \ u4e00& # 39;,以及uchar<=u # 39; \ u9fa5& # 39;:,   ,,,return  True    ,,:   ,,,return  False    ,   def  is_number (uchar):,   “““判断一个unicode是否是数字“““,   if 才能;uchar 祝辞=,u # 39; \ u0030& # 39;,以及uchar<=u # 39; \ u0039& # 39;:,   ,,,return  True    ,,:   ,,,return  False    ,   def  is_alphabet (uchar):,   “““判断一个unicode是否是英文字母“““,   if 才能;(uchar 祝辞=,u # 39; \ u0041& # 39;,以及uchar<=u # 39; \ u005a& # 39;),或(uchar 祝辞=,u # 39; \ u0061& # 39;,以及uchar<=u # 39; \ u007a& # 39;):,   ,,,return  True    ,,:   ,,,return  False    ,   def  is_other (uchar):,   “““判断是否非汉字,数字和英文字符“““,   if 才能;not  (is_chinese (uchar),或是is_number (uchar),或是is_alphabet (uchar)):,   ,,,return  True    ,,:   ,,,return  False    ,   def  B2Q (uchar):,   “““半角转全角“““,   inside_code才能=奥德(uchar),   if 才能;inside_code<0 x0020 或是inside_code> 0 x7e:, #不是半角字符就返回原来的字符,   ,,,return  uchar    if 才能inside_code==0 x0020:, #除了空格其他的全角半角的公式为:半角=全角0 xfee0    ,,,inside_code=0 x3000    ,,:   ,,,inside_code +=0 xfee0    return 才能unichr (inside_code),   ,   def  Q2B (uchar):,   “““全角转半角“““,   inside_code才能=奥德(uchar),   if 才能inside_code==0 x3000:,   ,,,inside_code=0 x0020    ,,:   ,,,inside_code -=0 xfee0    if 才能;inside_code<0 x0020 或是inside_code> 0 x7e:, #转完之后不是半角字符返回原来的字符,   ,,,return  uchar    return 才能unichr (inside_code),   ,   def  stringQ2B (ustr):,   “““把字符串全角转半角“““,   return “才能“. join ([Q2B (uchar), for  uchar 拷贝ustr)),   ,   def 制服(ustr):,   “““格式化字符串,完成全角转半角,大写转小写的工作“““,   return 才能stringQ2B (ustr) .lower (),   ,   def  string2List (ustr):,   “““将美国贸易代表办公室按照中文、字母,数字分开“““,   retList=[],   utmp=[],   for  uchar 美国贸易代表办公室拷贝:   if  is_other (uchar):,   if  len (utmp)==0:,   continue    其他:   retList.append . join (utmp)) (““,   utmp=[],   其他:   utmp.append (uchar),   if  len (utmp) !=0:,   retList.append . join (utmp)) (““,   return  retList

看完了这篇文章,相信你对“python根据unicode判断语言类型的示例分析”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!

python根据unicode判断语言类型的示例分析