# bytes object
b = b'n02509815'
# str object
s = "example"
# str to bytes编码
str.encode(s)#此时和b相等
# bytes to str解码
bytes.decode(b)#此时和s相等python2字符编码
最新推荐文章于 2024-07-02 17:31:10 发布
本文介绍了Python中字符串对象和字节对象的基本概念及其相互转换的方法。包括如何使用str.encode()将字符串编码为字节对象,以及如何使用bytes.decode()将字节对象解码为字符串。这对于理解Python的数据类型及编码处理非常重要。
1002

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



