您的位置:首页 > 编程语言 > Python开发

python基础:string和bytes数据类型之间的转换

2018-06-04 10:47 627 查看
版权声明: https://blog.csdn.net/ninnyyan/article/details/80564225

一个很简单的问题,但是曾经因为这个很闹心了一会,把简单的解决方案记录在这里。

string = 'adidas NMD_XR1 Shoes - Grey | adidas UK'
print('type of string: ',type(string))
# string to bytes
new = string.encode(encoding='unicode-escape')

print('type of new: ',type(new))

# bytes to string
emm = string.encode('utf-8').decode('unicode_escape')

print('type of emm: ',type(emm))

output:

type of string:  <class 'str'> 
type of new: <class 'bytes'>
type of emm: <class 'str'>

阅读更多
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: