str 转 bytes
非原创,复制转载。
写的巨好,每次都找这个文章,每次都找好久,这次记下来,emmm.....记下来
bytes object
b = b"example"
str object
s = "example"
str to bytes
sb = bytes(s, encoding="utf8")
bytes to str
bs = str(b, encoding="utf8")
an alternative method
str to bytes
sb2 = str.encode(s)
bytes to str
bs2 = bytes.decode(b)

浙公网安备 33010602011771号