python--unicodedata用法
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                python--unicodedata用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                python–unicodedata用法
需要掌握的
#1、將Unicode字符(chr)轉換為等效的數值。以浮點形式返回 print(unicodedata.numeric('四'))#4.0#2、 將unicode字符(chr)轉換為其等效的數字值。以整數形式返回 print(unicodedata.digit('8')) #8 print(unicodedata.digit('h',5)) #5 # print(unicodedata.digit('h') #SyntaxError: invalid syntax# 3、將unicode字符(chr)轉換為其等效的十進制值。以整數形式返回 print(unicodedata.decimal('5')) # 成功,返回5 print(unicodedata.decimal('a', 0)) # 未找到,返回默認值0 # print(unicodedata.decimal('a')) # 未找到,且未指定默認值,所以拋出ValueError異常 #4、返回當前unicod e使用的數據庫的版本 unicodedata.unidata_version了解
# 1、根據name去查找所對應的符號,找不到就報異常 print(unicodedata.lookup('LEFT CURLY BRACKET')) # { print(unicodedata.lookup('RIGHT CURLY BRACKET')) # } # 2、根據符號去找name print(unicodedata.name('!')) # FULLWIDTH EXCLAMATION MARK print(unicodedata.name('z')) # LATIN SMALL LETTER Z print(unicodedata.name('\t', 0)) # 未找到對應名稱,返回'0' # print(unicodedata.name('\t')) #ValueError: no such name # 3、返回字符chr在unicode里分類的類型。具體類型見文檔結尾附錄1。 print(unicodedata.category("d")) print(unicodedata.category("8")) print(unicodedata.category("伍")) #4、返回字符顯示的寬度。具體內容如下: # 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進制的值并返回,如果不可分解,返回空。 print(unicodedata.decomposition('é')) # 可分解 print(unicodedata.decomposition('e')) # 不可分解,所以返回空值(輸出就是一片空白)總結
以上是生活随笔為你收集整理的python--unicodedata用法的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: C语言strtok_r和strtok使用
 - 下一篇: MobCtrl.exe服务器端软件下载