# bytes object
b = b"11223344"
# str object
s = "xsophiax"
# str to bytes
stb = bytes(s, encoding = "utf8")
print(stb)
# bytes to str
bts = str(b, encoding = "utf8")
print(bts)
# an alternative method
# str to bytes
stb2 = str.encode(s)
print(stb2)
# bytes to str
bts2 = bytes.decode(b)
print(bts2)
输出
b'xsophiax'
11223344
b'xsophiax'
11223344