python3字符串编码

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/bubblelone/article/details/72793696

以此记录:


Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 16:02:32) [MSC v.1900 64 bit (AMD64)] on win32
>>>'的'
'的'


>>>'的'.encode()
b'\xe7\x9a\x84'


>>>'ab'.encode()
b'ab'


>>>'的'.encode(encoding='gb2312')
b'\xb5\xc4'


>>>'ab'.encode(encoding='gb2312')
b'ab'


>>>'的'.encode('unicode-escape')
b'\\u7684'


>>>'\u7684'
'的'


>>>b'\u7684'
b'\\u7684'


>>>b'\u7684'.decode('unicode-escape')

'的'


>>>b'\u7684'.decode()
'\\u7684'


>>>b'\u7684'.decode(encoding='gb2312')
'\\u7684'


猜你喜欢

转载自blog.csdn.net/bubblelone/article/details/72793696