英文文檔
chr(i)
Return the string representing a characterwhose Unicode code point is the integer i. For example, chr(97) returns thestring ‘a(chǎn)’, while chr(8364) returns the string ‘€’. This is the inverse oford().
The valid range for the argument is from 0through 1,114,111 (0x10FFFF in base 16). ValueError will be raised if i isoutside that range.
chr(i)
1、函數(shù)返回整形參數(shù)值所對(duì)應(yīng)的Unicode字符的字符串表示
>>> chr(97) #參數(shù)類型為整數(shù)
'a'
>>> chr('97') #參數(shù)傳入字符串時(shí)報(bào)錯(cuò)
Traceback (most recent call last):
? File "", line 1, in
? ? chr('97') #參數(shù)傳入字符串時(shí)報(bào)錯(cuò)
TypeError: an integer is required (got type str)
>>> type(chr(97)) #返回類型為字符串
2、它的功能與ord函數(shù)剛好相反
3、傳入的參數(shù)值范圍必須在0-1114111(十六進(jìn)制為0x10FFFF)之間,否則將報(bào)ValueError錯(cuò)誤
>>> chr(97)
'a'
>>> ord('a')
97
?
>>> chr(-1) #小于0報(bào)錯(cuò)
Traceback (most recent call last):
?File "
", line 1, in ???chr(-1) #小于0報(bào)錯(cuò)
ValueError: chr() arg not inrange(0x110000)
>>> chr(1114111)
'\U0010ffff'
>>> chr(1114112) #超過1114111報(bào)錯(cuò)
Traceback (most recent call last):
?File "
", line 1, in ???chr(1114112) #超過1114111報(bào)錯(cuò)
ValueError:chr() arg no
小結(jié)
希望通過上面的操作能幫助大家。如果你有什么好的意見,建議,或者有不同的看法,希望你留言和我進(jìn)行交流、討論。
歡迎關(guān)注微信公眾號(hào),訪問更多精彩: 數(shù)據(jù)之魅 。
如需轉(zhuǎn)載,請(qǐng)聯(lián)系授權(quán),謝謝合作。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
