首页 > IT职业 > IT生活 > python bytes 和 str的互转
# bytes object
b = b"example"
# str object
s = "example"
# str to bytes
bytes(s, encoding = "utf8")
# bytes to str
str(b, encoding = "utf-8")
# an alternative method
# str to bytes
str.encode(s)
# bytes to str
bytes.decode(b) 来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1805/viewspace-2807947/ ,如需转载,请注明出处,否则将追究法律责任。