python3 中如何进bytes串转换成str?

比如:
a = b'123'
想变成:
a = '123'

bytes解码会得到str

str编码会变成bytes

>>> b'123'.decode('ascii')
'123'
>>> '123'.encode('ascii')
b'123'

温馨提示:内容为网友见解,仅供参考
第1个回答  2017-09-12
Python 3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170118] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> a = b'123'
>>> a.decode()
'123'

第2个回答  2017-10-12
b'123'.decode()
结果是'123'
相似回答