Variable = u "x"
U: represents Unicode
Python3 will become bys byte type after transcoding
Case
1 #-*-CODING:GBK-*-2A ="Hello"3 Print(a)4 Print(A.encode ("GBK"))5 Print(A.encode ("Utf-8"))6 Print(A.encode ("Utf-8"). Decode ("Utf-8"). Encode ("gb2312"). Decode ("gb2312"))
Output
Python3 transcoding
Note: When the software is converted to GBK display under Python3, the character is actually utf-8 only the character of the file has changed,
Does not directly change the character encoding within the Python3, the error is utf-8 not recognize the file modification characters, not recognized is the command.
Note: sys.getdefaultencoding () indicates that the encoding type is displayed.
Note: Encoding conversion requires XI ' an to convert to Unicode and then transcode.
Note: If the UTF8 does not need to be transferred, UTF8 is an extension of Unicode.
Python character encoding