python str与bytes之间的转换

python str与bytes之间的转换,代码如下:

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

出处:www.l1mn.com

原文标题:python str与bytes之间的转换

原文地址:https://www.l1mn.com/p/iz26q4.html

本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

分类:python
标签:python
评论

皖ICP备2023023451号

Copyright © L1MN.COM 联系方式:l1mnfw@163.com