"Python3" character decoding and encoding

Source: Internet
Author: User

1.the variable declared by PY3 is Unicode encoded by default , and the default file encoding is Utf-8

2.unicode is divided into utf-32 (4 bytes), utf-16 (Accounting for 2 bytes), Utf-8 (1-4 bytes), so utf-16 is now the most commonly used Unicode version, but in the file is still utf-8, because the Utf-8 save space

3. In the Py3 encode, at the same time transcoding will also change the string into bytes type, decode in the decoding will also turn bytes back to string, in Py3, str and bytes made a clear distinction

Str=u ' Good study day up ' #加u表示unicode, default is Unicode

Utf-8_to _GBK = Str.decode (' Utf-8 '). Encode (' GBK ')

"Python3" character decoding and 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.