python之encode和decode编码


u = '中文'
str3 = u.encode('utf-8')
# 以utf-8编码对u进行编码,获得bytes类型对象
print(str3)

u2 = str3.decode('utf-8')
# 以utf-8编码对str3进行解码,获得str类型对象
print(u2)


#打印结果如下:
b'\xe4\xb8\xad\xe6\x96\x87'
中文

posted @ 2019-09-11 22:42  大海一个人听  阅读(137)  评论(0编辑  收藏  举报