牛骨文教育服务平台(让学习变的简单)
博文笔记

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

创建时间:2015-04-23 投稿人: 浏览次数:153
# 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)  


声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。