TYT的网站

python str与bytes之间的转换

2018-02-25 01:32 Python· 点击 663
# 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)


返回列表
浏览 新增 设置