码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-08-26 21:31:27      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:http   example   alt   转换   native   encoding   span   nat   style   

原文: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   example   alt   转换   native   encoding   span   nat   style   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!