python字符串str和字节数组bytes相互转化

1 引言

后续待补充

2 代码

b = b"Hello, world!"  # bytes  
s = "Hello, world!"   # string

print('str --> bytes')
print(bytes(s, encoding="utf8"))   
print(bytes(s))  #默认utf8编码

print('bytes --> str')
print(str(b, encoding="utf-8"))  
print(str(b))    #默认utf8编码
原文地址:https://www.cnblogs.com/fanbi/p/10026035.html