python中bytes与str的互转
前言
实现bytes与str的互相转换
使用
# 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)
# b
原创
2020-09-26 17:16:26 ·
117 阅读 ·
0 评论