阅读背景:

Python字符和字节之间的相互转换

来源:互联网 
b = b"Hello, world!"  # bytes object  
s = "Hello, world!"   # str object 

print('str --> bytes')
print(bytes(s, encoding="utf8"))    
print(str.encode(s))   # 默认 encoding="utf-8"
print(s.encode())      # 默认 encoding="utf-8"

print('\nbytes --> str')
print(str(b, encoding="utf-8"))   
print(bytes.decode(b))  # 默认 encoding="utf-8"
print(b.decode())       # 默认 encoding="utf-8"b = b"Hello, world!"  # bytes object  
s = "



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: