import hashlib
#字节对象b
b = b"example"
#字符串对象s
s = "example"
print(b)
print("example")
字符串->字节
b2 = bytes(s,encoding='utf8') #必须制定编码格式
# print(b2)
b3 = str.encode(s)
print(b3)
print(type(b3))
b4 = s.encode()
print(b4)
字节->字符串
#将字节对象decode将获得一个str对象
s2 = bytes.decode(b)
print(s2)
s3 = b.decode()
print(s3)
网友评论