首页 > 编程语言 > 详细

[转]python str与bytes之间的转换

时间:2017-08-26 21:19:20      阅读:289      评论:0      收藏:0      [点我收藏+]

原文:http://www.cnblogs.com/zqifa/p/python-7.html

# bytes object 
b = b"example"

# str object 
s = "example"

# str to bytes 
sb = bytes(s, encoding = "utf8")

# bytes to str 
bs = str(b, encoding = "utf8")

# an alternative method 
# str to bytes 
sb2 = str.encode(s)

# bytes to str 
bs2 = bytes.decode(b)

 

[转]python str与bytes之间的转换

原文:http://www.cnblogs.com/tinyos/p/7436324.html

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