一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

python字符串str和字节数组相互转化方法

时间:2017-07-06 编辑:简简单单 来源:一聚教程网

 
 代码如下复制代码
# 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)
 

热门栏目