Python Basics About Encoding

Source: Internet
Author: User

One, the type of code:

1 Acsic code basic without different coding between the interoperability will produce garbled,

2unicode a letter 4 bytes 00000000 00000000 00100100 01000000

Chinese 4 bytes 00000000 00000000 00100100 00000000

3utf-8 Chinese A letter 1 byte 00000001

Europe 2 Bytes 00000000 00000000 00100100 00000000

Asian Chinese 3 Bytes 00000000 00000000 00000000 00100100 00000000

       

4 gbk A letter 2 Bytes 00000000 00001000

Chinese Asian 2 bytes 00100100 00000000

Two: The difference between byte (bytes) and string (str):

Bytes: representation: s = ' Q ' b1 = S.encode (' utf-8 ') print (B1) B1 = B ' Q '

Internal storage is (Utf-8, GBK, gb232, etc.)

s1 = ' Xiao Mei '

B11 = S1.encode (' utf-8 ')

Representation: s = B ' \xe6\x99\x93\xe6\xa2\x85 ' (utf-8,gbk,gb2312 ... ) 010101

             0000 1000 0000 0000 0000 0001 0000 1001 0000 0000 0000 0001
Note: In the case of Utf-8 B there are 6 (E6 99, etc.) said the name of Xiao Mei is Chinese utf-8 is two words 6 bytes
    

S2 = ' Xiao Mei '
     B22 = S1.encode(' GBK ')
Print (B22)
B ' \xcf\xfe\xc3\xb7 '
Representation: s = B ' \xcf\xfe\xc3\xb7 ' (utf-8,gbk,gb2312 ... ) 010101
0000 1000 0000 0000 0000 0001 0000 1001
  Note: In the case of GBK B there are 4 (cf XF, etc.) said the name of Xiao Mei is Chinese GGBK is two words 4 bytes
Str  The representation of  s = "Wangyan '  internal storage is (Unicode)

ID (memory address) = = is the value of the comparison
List Dictionary meta-ancestor set memory address is not the same
      Small Data pool for int
int: Range: -5---The same number created by the first, pointing to the same memory address. Except spaces
STR: Strings generally point to the memory address you want to have, except for spaces.

s = ' Alex '
Print (S,type (s))
Print (S,type (s), ID (s)) Alex <class ' str ' > 51749664

if S1 = S2 = ' Wangyan '
Print (S1 = s2)
Print (S1 is S2)

       Small Data pool for int
int: Range: -5---The same number created by the first, pointing to the same memory address.




Python Basics About Encoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.