Python之a(chǎn)scii轉(zhuǎn)中文的實(shí)現(xiàn)
發(fā)布日期:2022-06-20 14:28 | 文章來源:CSDN
看代碼吧~
name = r"\u6697\u88d4\u5251\u9b54"
print(name.encode('ascii').decode('unicode_escape'))
或
print(name.encode().decode('unicode_escape'))
補(bǔ)充:python 漢字與ASCII互相轉(zhuǎn)換
一、代碼段
#python ASCII轉(zhuǎn)漢字 name = r"\u5f20\u5357\u74dc" print(name.encode(‘a(chǎn)scii').decode(‘unicode_escape')) #python 漢字轉(zhuǎn)ASCII name1=“張南瓜” print(name1.encode(‘unicode_escape').decode(‘a(chǎn)scii'))
二、運(yùn)行結(jié)果:

利用的是python中的encode()和decode()函數(shù),具體的原理和細(xì)節(jié)我還沒有弄清楚,記錄下
補(bǔ)充:python Unicode /ASCII轉(zhuǎn)utf-8( 中文)
decode(‘unicode-escape')
例如:
str='\u5927\u592b' str.encode(‘utf-8').decode(‘unicode-escape')
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信