数字转字符 - chr() 字符转数字 - ord() 于是就出现一个有意思的事情,chr()可以将数字转化为字符,而且根据python3的IDLE提示,chr()的范围为0<=i<=0x10ffff,如果我们遍历这之间的数值会有什么现象呢,如下:
1 2 3 4 5 6 7 8 9 10 |
for i in range(0,0x10ffff): print(format("%6X: %s") % (i, chr(i)) ) ----------------------------------------------------------------------- FFFF: <br>Traceback (most recent call last): File "C:\Users\jma\Desktop\chr.py", line 9, in <module> print(format("%10X: %s") % (i, chr(i)) ) UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 12-12: Non-BMP character not supported in Tk |
在超过65535的时候,系统就提示错误了,可是同样的程序在cmd里面却可 […]