About Python decode () and encode ()

Source: Internet
Author: User

1. First gather the usage of the decode () decoding and Encode () codes seen in the past few days

Bytes and STR are byte packets and strings, and Python3 will distinguish between bytes and STR, and will not mix these two. A string can be encoded into a byte packet, and a byte packet can be decoded into a string.

As follows

Illegal! is a string that is encoded into a byte packet and can see B ' this identity.

We don't care how they are represented internally, and each character in the string is saved in a few bytes. It is only when the strings are encoded into a byte package (for example, to send them on a channel) or decoded from a byte packet (reverse operation) that we begin to pay attention to this.

If the content of a page is read in bytes, it needs to be decoded into a string, JSON format, which requires a string. If the data being read is a JSON-formatted string, we can use the loads method in the module JSON provided by Python to turn it into a dictionary.

Cross-conversion between different encodings in 2.python

in Python, the Unicode type is used as the underlying type of the encoding, i.e. Decode encode

str ———— > Unicode ———— > str

About Python decode () and encode ()

Related Article

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.