#coding =utf-8
A = "You" # This string is unicode and a = u "You" equivalent
b = B ' \\u4f60 ' #这个表示b是字节串 (Print (B.decode ("Unicode-escape"))) system will return "you" if you need to display the value of B because it decodes you based on Utf-8.
Print (A.encode ("Unicode-escape")) #这个表示a这个字符串编码成Unicode的字节串 The return value is B ' \\u4f60 '
Print (' \u4f60 ') #等价于 print (a) is equivalent to print (' you '), and the system will do the following when it is actually played
Print (' \u4f60 '. Encode ("Utf-8"). Decode ("Utf-8"))
#python默认使用utf-8 encoding, converts Unicode characters to utf-8 format, and then looks at the value of the codepage table to display the string "You"
Here's a long-time brain problem.
Print (b ' \u4f60 '. Decode ("Unicode-escape")) #返回 "You", where B ' \u4f60 ' is a Unicode byte string, so it needs to be decoded into Unicode characters
Print (' \u4f60 '. Encode ("Utf-8"). Decode ("Utf-8")) #返回 "You" Here "\u4f60" and "you" equivalent, encode Unicode into utf-8 format, then decode "You" according to the codepage table
The following because of the dead, so confuse themselves, figured out after finishing the content as follows.
The "You" Unicode byte string is B ' \\u4f60 '
The utf-8 byte string of "You" is B ' \xe4\xbd\xa0 '
Since Python3 is a Unicode format, the default encoding format is Utf-8
So print (' \u4f60 ') defaults to decoding it as a Unicode format to the Utf-8 string to display.
So the personal understanding is that print (' \u4f60 ') prints the return value to the user to view the operation of the computer is print (' \u4f60 '. Encode ("Utf-8"). Decode ("Utf-8"))
Print (' \xe4\xbd\xa0 ') is garbled because it is garbled in the Unicode codepage table (unless Python turns the string into utf-8 format, "You" can be displayed normally)
Python3 Coding Problem Personal understanding