Python 基础知识整理-3 (bytes-strings)

mac2022-06-30  17

strings 分别在 Python2、Python 3下

Python 2 将 strings 处理为原生的 bytes 类型,而不是 unicode, Python 3 所有的 strings 均是 unicode 类型。

 

 

msg = '您好' # encode 将strings编码成bytes print(msg.encode('utf-8')) # decode 将bytes 解码成strings print(b'\xe6\x82\xa8\xe5\xa5\xbd'.decode('utf-8'))

print 结果

 

转载于:https://www.cnblogs.com/Linc2010/p/8294967.html

最新回复(0)