英文文檔
chr(i)
Return the string representing a characterwhose Unicode code point is the integer i. For example, chr(97) returns thestring ‘a’, 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、函數返回整形參數值所對應的Unicode字符的字符串表示
>>> chr(97) #參數類型為整數
'a'
>>> chr('97') #參數傳入字符串時報錯
Traceback (most recent call last):
? File "", line 1, in
? ? chr('97') #參數傳入字符串時報錯
TypeError: an integer is required (got type str)
>>> type(chr(97)) #返回類型為字符串
2、它的功能與ord函數剛好相反
3、傳入的參數值范圍必須在0-1114111(十六進制為0x10FFFF)之間,否則將報ValueError錯誤
>>> chr(97)
'a'
>>> ord('a')
97
?
>>> chr(-1) #小于0報錯
Traceback (most recent call last):
?File "
", line 1, in ???chr(-1) #小于0報錯
ValueError: chr() arg not inrange(0x110000)
>>> chr(1114111)
'\U0010ffff'
>>> chr(1114112) #超過1114111報錯
Traceback (most recent call last):
?File "
", line 1, in ???chr(1114112) #超過1114111報錯
ValueError:chr() arg no
小結
希望通過上面的操作能幫助大家。如果你有什么好的意見,建議,或者有不同的看法,希望你留言和我進行交流、討論。
歡迎關注微信公眾號,訪問更多精彩: 數據之魅 。
如需轉載,請聯系授權,謝謝合作。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

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