Decode is decoding, encode encoding
ASCLL in Python2 by default when Unicode is default in Python3
GBK steering Utf-8: First decode the GBK into Unicode, encoded into utf-8.
Utf-8 steering GBK: First decode the utf-8 into Unicode, encoded into GBK.
Python2 Code:
1 #-*-coding:utf-8-*-2 3 " "4 @auther: Starry5 @file: py2ende.py6 @time: 18-1-12 pm 9:527 " "8 9 " "Ten ASCII is the default in Python2 One " " A ImportSYS - - Print(Sys.getdefaultencoding ()) the -s ='Hello' - -S_unicode = S.decode ('Utf-8') +S_GBK = S_unicode.encode ('GBK') - + Print(S_unicode) A Print(S_GBK) at -Gbk_to_utf8 = S_gbk.decode ('GBK'). Encode ('Utf-8') - Print(Gbk_to_utf8)
Python3 Code:
1 #!/usr/bin python3.52 #-*-coding:utf-8-*-3 4 " "5 @auther: Starry6 @file: py3ende.py7 @time: 18-1-12 pm 9:568 " "9 Ten " " One default Unicode in Python3 A " " - - ImportSYS the Print(Sys.getdefaultencoding ()) - - -s ='Hello' + Print(s) - + AS_utf8 = S.encode ('Utf-8') atS_GBK = S.encode ('GBK') - - Print(S_utf8) - Print(S_GBK) - -Gbk_unicode = S_gbk.decode ('GBK') in Print(Gbk_unicode) - toUTF8_TO_GBK = S_utf8.decode ('Utf-8'). Encode ('GBK') +Gbk_to_utf8 = S_gbk.decode ('GBK'). Encode ('Utf-8') - the Print(UTF8_TO_GBK) * Print(Gbk_to_utf8)
Python Decoding and encoding