Python encoding Processing: Unicode byte string translated into Chinese various strings example description

Source: Internet
Author: User
Tags ord

Coding problem has always been a headache problem:

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: ' & #19996;& #20122;& #23398;& #22242;& #19968;& #20013; '

>>>print UNICHR (19996)

East

Ord () supports Unicode, which can display Unicode numbers for specific characters, such as:

>>>print Ord (' A ') 65

Unicode strings are generated as long as they are connected to Unicode. Such as:

>>> ' Help ' "Help" >>> ' help, ' + u ' python '     u ' help,python '

for ASCII (7-bit)-compatible strings, the Unicode string can be converted to an ASCII string with the built-in STR () function. such as:

>>> str (U ' Hello World ') ' Hello World '

An understanding of several concepts:

ASCII: corresponds to the corresponding character with the data word

And the Chinese is the location code corresponding to Chinese characters such as: "Good" ASCII code is: 22909

Unicode encoding is a piece of each country. It has UTF-8, UTF-16, UTF-32 and other forms

Chinese range 4E00-9FBF: There are gbk,gb2312 in this range,

Utf-8 is a Unicode-based international occasion for use
GB2312 and gb2312 are both of them. Earlier mainly used to encode and decode commonly used Chinese characters

Python encoding Processing: Unicode byte string translated into Chinese various strings example description

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.