encode/decode/bytes

python3中如何将字符型转换成utf-8格式的bytes类型

  

str_me = '字符是我'.encode('utf-8')


print(str_me)

>>:b'\xe5\xad\x97\xe7\xac\xa6\xe6\x98\xaf\xe6\x88\x91'

在python3 中如何把utf-8格式的bytes解码成str

str_me=b'\xe5\xad\x97\xe7\xac\xa6\xe6\x98\xaf\xe6\x88\x91'

str_me = str_me.decode('utf-8')

print(str_me)

>>:字符是我

猜你喜欢

转载自www.cnblogs.com/yanxiatingyu/p/9254255.html
今日推荐