# 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)python str与bytes之间的转换
最新推荐文章于 2025-09-06 10:19:41 发布
本文介绍了Python中字符串对象与字节对象之间的相互转换方法,包括使用特定编码将字符串转换为字节串以及如何将字节串解码回字符串。
2687

被折叠的 条评论
为什么被折叠?



