The default character encoding in Python3 is Unicode and can be encode directly to other encodings
The default in Python2 is GBK under Windows, all non-Unicode first decode to Unicode, and then encode to other character encodings.
Borrowing diagram
ImportSYSPrint(Sys.getdefaultencoding ())#Display character encodingA_unicode="the end of yuqingping from the wind" #This is the Unicode formatPrint(a_unicode) A_GBK=a_unicode.encode ('GBK')#default is Unicode format, converted to GBK formatPrint(A_GBK) a_gb2312=a_gbk.decode ('GBK'). Encode ('gb2312')#first decode converted to Unicode format, the parentheses tell themselves to be GBK format, and then encode conversion, in parentheses to write the format to be converted. Print(a_gb2312)#GBK is the gb2312 upgrade version, commonly used Chinese characters encoding basically the sameA_unicode2=a_gbk.decode ('GBK')#Convert to Unicode formatPrint(A_UNICODE2)
Character encoding and transcoding