python--unicodedata用法
生活随笔
收集整理的這篇文章主要介紹了
python--unicodedata用法
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
python–unicodedata用法
需要掌握的
#1、將Unicode字符(chr)轉(zhuǎn)換為等效的數(shù)值。以浮點(diǎn)形式返回 print(unicodedata.numeric('四'))#4.0#2、 將unicode字符(chr)轉(zhuǎn)換為其等效的數(shù)字值。以整數(shù)形式返回 print(unicodedata.digit('8')) #8 print(unicodedata.digit('h',5)) #5 # print(unicodedata.digit('h') #SyntaxError: invalid syntax# 3、將unicode字符(chr)轉(zhuǎn)換為其等效的十進(jìn)制值。以整數(shù)形式返回 print(unicodedata.decimal('5')) # 成功,返回5 print(unicodedata.decimal('a', 0)) # 未找到,返回默認(rèn)值0 # print(unicodedata.decimal('a')) # 未找到,且未指定默認(rèn)值,所以拋出ValueError異常 #4、返回當(dāng)前unicod e使用的數(shù)據(jù)庫(kù)的版本 unicodedata.unidata_version了解
# 1、根據(jù)name去查找所對(duì)應(yīng)的符號(hào),找不到就報(bào)異常 print(unicodedata.lookup('LEFT CURLY BRACKET')) # { print(unicodedata.lookup('RIGHT CURLY BRACKET')) # } # 2、根據(jù)符號(hào)去找name print(unicodedata.name('!')) # FULLWIDTH EXCLAMATION MARK print(unicodedata.name('z')) # LATIN SMALL LETTER Z print(unicodedata.name('\t', 0)) # 未找到對(duì)應(yīng)名稱,返回'0' # print(unicodedata.name('\t')) #ValueError: no such name # 3、返回字符chr在unicode里分類的類型。具體類型見(jiàn)文檔結(jié)尾附錄1。 print(unicodedata.category("d")) print(unicodedata.category("8")) print(unicodedata.category("伍")) #4、返回字符顯示的寬度。具體內(nèi)容如下: # F:fullwidth,H:halfwidth,W:wide,Na:narrow,A:ambiguous(不明確),N:natural(正常) print(unicodedata.east_asian_width('我'))# 5、判斷字符chr是否支持鏡像屬性,支持則返回1,不支持則返回0print(unicodedata.mirrored('0')) #0 print(unicodedata.mirrored('王'))#0#6、將一個(gè)可分解的字符chr分成兩個(gè)16進(jìn)制的值并返回,如果不可分解,返回空。 print(unicodedata.decomposition('é')) # 可分解 print(unicodedata.decomposition('e')) # 不可分解,所以返回空值(輸出就是一片空白)總結(jié)
以上是生活随笔為你收集整理的python--unicodedata用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C语言strtok_r和strtok使用
- 下一篇: 【Python】Jupyter Note