日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

python--unicodedata用法

發(fā)布時間:2023/12/20 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python--unicodedata用法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

python–unicodedata用法

需要掌握的

#1、將Unicode字符(chr)轉(zhuǎn)換為等效的數(shù)值。以浮點形式返回 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ù)庫的版本 unicodedata.unidata_version

了解

# 1、根據(jù)name去查找所對應(yīng)的符號,找不到就報異常 print(unicodedata.lookup('LEFT CURLY BRACKET')) # { print(unicodedata.lookup('RIGHT CURLY BRACKET')) # } # 2、根據(jù)符號去找name print(unicodedata.name('!')) # FULLWIDTH EXCLAMATION MARK print(unicodedata.name('z')) # LATIN SMALL LETTER Z print(unicodedata.name('\t', 0)) # 未找到對應(yīng)名稱,返回'0' # print(unicodedata.name('\t')) #ValueError: no such name # 3、返回字符chr在unicode里分類的類型。具體類型見文檔結(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、將一個可分解的字符chr分成兩個16進(jìn)制的值并返回,如果不可分解,返回空。 print(unicodedata.decomposition('é')) # 可分解 print(unicodedata.decomposition('e')) # 不可分解,所以返回空值(輸出就是一片空白)

總結(jié)

以上是生活随笔為你收集整理的python--unicodedata用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。