Encode (), decode () character encoding issues

Source: Internet
Author: User

Python3, changed the default encoding, changed in order to Unicode

Prerequisite Knowledge:

    1. Utf-8 relationship to Unicode: Https://baike.baidu.com/item/UTF-8/481798?fr=aladdin
    2. The \x represents the hexadecimal data.
    3. Encode default is Utf-8, the right figure in the \x corresponding to the Unicode to UTF-8 encoded data:
    4. UTF-8: Use 1, 2, 3, 4 bytes for all characters, a priority of 1 characters, not enough to increase one byte, up to 4 bytes. English accounts for 1 bytes, European languages accounted for 2, East Asia accounted for 3, other and special characters accounted for 4
    5. Unicode has a large capacity, and almost all other encodings have mappings on them, such as the Chinese encoding method GBK
    6. , so the ' medium ' encoding in Unicode is 20013

Python3 STR is Unicode, used in binary, 16, and other formats bytes

Decode is to tell Unicode what you are coding:

The result of encode is a bytes object: a hexadecimal representation of the corresponding character's various encoding methods

The following is the result of encode in GBK format:

So the decode and encode are actually:

Encode (), decode () character encoding issues

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.