python的编码转换函数
【案例题】
若要想查看汉字‘好’的unicode编码的十六进制的表示形式,并打印输出到屏幕,改如何编码
alpha = '好'
print(hex(ord(alpha)))
#--result
#0x597d
x = ascii(alpha)
print(x)
#--result
#'\u597d'
你题目的解答代码如下:
c = '好'
v = f"{ord(c):x}"
print(v) #输出 597d
# 或者
print(hex(ord(c))[2:])
print(chr(int(v,16))) #还原"好"
如有帮助,请点击我的回答下方的【采纳该答案】按钮帮忙采纳下,谢谢!