首页 > 编程语言 > 详细

python str与bytes之间的转换

时间:2018-01-20 23:31:14      阅读:227      评论:0      收藏:0      [点我收藏+]
 1 # bytes object  
 2  b = b"example"  
 3   
 4  # str object  
 5  s = "example"  
 6   
 7  # str to bytes  
 8  bytes(s, encoding = "utf8")  
 9   
10  # bytes to str  
11  str(b, encoding = "utf-8")  
12   
13  # an alternative method  
14  # str to bytes  
15  str.encode(s)  
16   
17  # bytes to str  
18  bytes.decode(b)  

 

python str与bytes之间的转换

原文:https://www.cnblogs.com/zhouxinfei/p/8322225.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!