0
点赞
收藏
分享

微信扫一扫

Python str与bytes之间的转换

醉东枫 2022-02-10 阅读 88


# 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)



举报

相关推荐

0 条评论