代码:
# -*- coding:utf-8 -*-
str = '\x35'.encode('hex')
print str
str = '5'.encode('hex')
print str
str = '56'.encode('hex')
print str
str = '37'.decode('hex')
print str
str = '3738'.decode('hex')
print str
#str = '37389'.decode('hex')
#print str
结果:
35
35
3536
7
78
Process finished with exit code 0
最后两行
#str = '37389'.decode('hex')
#print str
如果放开的话 会出错
本文通过Python代码示例展示了字符串的编码与解码过程,包括使用'hex'进行编码和解码的方法。该文适合初学者了解Python中字符串编码的基本操作。
1547

被折叠的 条评论
为什么被折叠?



