Character encoding and transcoding

Source: Internet
Author: User

The default character encoding in Python3 is Unicode and can be encode directly to other encodings

The default in Python2 is GBK under Windows, all non-Unicode first decode to Unicode, and then encode to other character encodings.

Borrowing diagram

ImportSYSPrint(Sys.getdefaultencoding ())#Display character encodingA_unicode="the end of yuqingping from the wind" #This is the Unicode formatPrint(a_unicode) A_GBK=a_unicode.encode ('GBK')#default is Unicode format, converted to GBK formatPrint(A_GBK) a_gb2312=a_gbk.decode ('GBK'). Encode ('gb2312')#first decode converted to Unicode format, the parentheses tell themselves to be GBK format, and then encode conversion, in parentheses to write the format to be converted. Print(a_gb2312)#GBK is the gb2312 upgrade version, commonly used Chinese characters encoding basically the sameA_unicode2=a_gbk.decode ('GBK')#Convert to Unicode formatPrint(A_UNICODE2)

Character encoding and transcoding

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.