Coding in Python

Source: Internet
Author: User

In programming languages, there are basically three ways to encode

Ascii

UTF-8

Unicode

There are local coding methods, such as China's GBK, etc.

where ASCII encoding is an early encoding method, where each character or English letter occupies one byte (8bit) leaving part of the space as an extension to use,

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/8C/1E/wKiom1hiXzWxLsT4AAXk5OCcZfA064.png-wh_500x0-wm_3 -wmp_4-s_3214994685.png "title=" qq picture 20161227203129.png "alt=" Wkiom1hixzwxlst4aaxk5occzfa064.png-wh_50 "/>

With the development of computer technology, more and more countries need to use their own language as a computer code, and the use of ASCII encoding method is more and more serious, in the later stage developed into various countries to use their own code, such as China using GBK encoding method.

When more and more coding, manageability and repeated coding more and more, the International Organization for Standardization has developed a Unicode (Chinese to universal Encoding) encoding, with 2 bytes as a code, but this kind of coding is too large to occupy a large amount of space resources, Native English-speaking countries, where a single byte of code is needed, it now takes two bytes to act as a waste of resources.

So on the basis of the development of another code namely: UTF-8, which can be easily understood as a simplified version of Unicode, combining the content of the ASCII and the Unicode content, that is, in ASCII encoding or 1 bytes as the encoding, Other extended content is encoded with 3 bytes


Conversions between individual encodings:

Conversion between codes, such as GBK to Utf-8, or utf-8 to GBK, needs to be converted to Unicode encoding first

In the python2.0, you need to first reputation code, in 3.0 the default encoding format is Unicode, the following is the declaration of the Encoding format

# _*_ Coding:utf-8 _*_


Conversion between encodings:

A = ' The Thief of the Forest '. Encode (' Utf-8 ') #默认编码是unicode可直接转utf-8





Coding in Python

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.