国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

python根據unicode判斷語言類型實例代碼

2020-02-22 22:53:50
字體:
來源:轉載
供稿:網友

本文實例主要實現的是python根據unicode判斷語言類型,具體如下。

實例代碼:

def is_chinese(uchar): """判斷一個unicode是否是漢字"""   if uchar >= u'/u4e00' and uchar<=u'/u9fa5':     return True   else:     return False  def is_number(uchar): """判斷一個unicode是否是數字"""   if uchar >= u'/u0030' and uchar<=u'/u0039':     return True   else:     return False  def is_alphabet(uchar): """判斷一個unicode是否是英文字母"""   if (uchar >= u'/u0041' and uchar<=u'/u005a') or (uchar >= u'/u0061' and uchar<=u'/u007a'):     return True   else:     return False  def is_other(uchar): """判斷是否非漢字,數字和英文字符"""   if not (is_chinese(uchar) or is_number(uchar) or is_alphabet(uchar)):     return True   else:     return False  def B2Q(uchar): """半角轉全角"""   inside_code=ord(uchar)   if inside_code<0x0020 or inside_code>0x7e: #不是半角字符就返回原來的字符     return uchar   if inside_code==0x0020: #除了空格其他的全角半角的公式為:半角=全角-0xfee0     inside_code=0x3000   else:     inside_code+=0xfee0   return unichr(inside_code)  def Q2B(uchar): """全角轉半角"""   inside_code=ord(uchar)   if inside_code==0x3000:     inside_code=0x0020   else:     inside_code-=0xfee0   if inside_code<0x0020 or inside_code>0x7e: #轉完之后不是半角字符返回原來的字符     return uchar   return unichr(inside_code)  def stringQ2B(ustring): """把字符串全角轉半角"""   return "".join([Q2B(uchar) for uchar in ustring])  def uniform(ustring): """格式化字符串,完成全角轉半角,大寫轉小寫的工作"""   return stringQ2B(ustring).lower()  def string2List(ustring): """將ustring按照中文,字母,數字分開""" retList=[] utmp=[] for uchar in ustring: if is_other(uchar): if len(utmp)==0: continue else: retList.append("".join(utmp)) utmp=[] else: utmp.append(uchar) if len(utmp)!=0: retList.append("".join(utmp)) return retList 

總結

以上就是本文關于python根據unicode判斷語言類型實例代碼的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站其他相關專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 祁阳县| 潮安县| 冕宁县| 浏阳市| 登封市| 万全县| 青河县| 军事| 故城县| 咸阳市| 青州市| 靖边县| 宜都市| 平陆县| 金寨县| 灵山县| 永和县| 玉环县| 丹巴县| 溧阳市| 枣强县| 林州市| 沅江市| 合水县| 吉木萨尔县| 淮滨县| 达日县| 甘泉县| 汾阳市| 兰州市| 宣汉县| 潼南县| 招远市| 温州市| 曲沃县| 彰武县| 高安市| 武夷山市| 子洲县| 静海县| 靖宇县|