Python如何将bytes转为str类型,如何将str转为bytes类型,我们需要用到encode函数、str函数、bytes函数,通过这几个函数就可以实现str和bytes之间的转换
先创建个bytes类型的把玩一下:
b = b"test"在创建一个str类型的把玩一下:
s = "test"str 转为 bytes
bytes(s, encoding = "utf8")bytes 转为 str
str(b, encoding = "utf-8")str 转为 bytes
str.encode(s)bytes 转为 str
bytes.decode(b)