Python Chinese encoding problem summary-Python tutorial

Source: Internet
Author: User
This article mainly introduces python Chinese encoding, which is a common problem in Python Programming. This article provides a detailed summary of this problem in the form of examples, if you need it, you can refer to the question of Chinese encoding, which has always been a headache in Python Programming. This article summarizes and summarizes this in detail. The details are as follows:

When the string is '\ u4e2d \ u56fd'

>>> S = ['\ u4e2d \ u56fd', '\ u6e05 \ u534e \ u5927 \ u5b66'] >>> str = s [0]. decode ('unicode _ escape ')#. encode ("EUC_KR") >>> print str China

When the string is: 'East Asian Study Group No. 1'

>>> Print unichr (19996) East

Ord () supports unicode and can display unicode numbers of specific characters, such:

>>>print ord('A')65

Unicode strings are generated as long as they are connected to Unicode. For example:

>>> 'help''help'>>> 'help,' + u'python'   u'help,python'

For ASCII (7-bit)-compatible strings, you can convert Unicode strings into ASCII strings with the built-in str () function. For example:

>>> str(u'hello world')'hello world'

Understanding of several concepts:

The ASCII code corresponds to the corresponding characters using data words, as shown in:

Chinese is the Chinese character corresponding to the location code. For example, the "good" ASCII code is 22909

Unicode encoding is divided into one field for each country. It has UTF-8, UTF-16, UTF-32 and other forms
The Chinese value range is 4E00-9FBF. gbk, gb2312,

UTF-8 is a unicode-based international application.

Gb2312 and gb2312 are both early Chinese character codes used for encoding and decoding.

I hope this article will help you with Python programming.

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.