Python3的unichr()消失了?不,升级了!

Python2中使用的chr()将Ascii的值转换成对应字符,unichr()将Unicode的值转换成对应字符
我们发现Python3中该内置函数消失了,实际上是Python3中的chr()不仅仅支持Ascii的转换,直接支持了更为适用的Unicode转换。

#输入Unicode编码起始值和终止值,打印此范围内所有字符
beg = int(input("请输入起始值:"))
end = int(input("请输入终止值:"))
print("十进制编码\t十六进制编码\t字符")
for i in range(beg,end+1):
    print("{}\t\t\t{}\t\t\t{}".format(i,hex(i),chr(i))) #hex()转十六进制 chr()求十进制或十六进制对应的字符

9472-9599为全部制表符可以测试一下

Unicode字符编码表:https://blog.csdn.net/zhenyu5211314/article/details/51537778

猜你喜欢

转载自blog.csdn.net/lly1122334/article/details/80598983