Python for Chinese encoding processing several ways

Source: Internet
Author: User

When we write programs or scripts, we will encounter the "Chinese" encoding problem, resulting in the entire program does not work properly, the ancient collation of all currently know "Python for Chinese encoding processing several ways", as follows:

#coding =utf-8# how Chinese output ' Python's Chinese Encoding ' #方法一: Head plus "#-*-coding:utf-8-*-" n = ' python's Chinese encoding Method 111111 ' Print n# Methods II: Header Plus ' #coding = Utf-8 "Print" Python's Chinese Encoding 222222 ' #方法三: Add a uprint u ' python to the text in Chinese encoding 333333 ' #方法四: Call the Encode () method import Sysreload (SYS) Sys.setdefaultencoding (' Utf-8 ') print n.encode (' utf-8 ') + ' 4444444 ' #方法五: Coercion type conversion, using Unicode () Print Unicode (' Python's Chinese encoding Method 5555555 ') #方法六: Coercion type conversion, using Unicode (s, encoding = ") List = [' Hello: ', ' python! '] Print Unicode (list[0], encoding= ' utf-8 ') + Unicode (list[1], encoding= ' utf-8 ') ' need to be aware that utf-8 is not everything, we need to keep scripts, browsers, The conversion between the three codes of the program; if Utf-8 cannot be resolved, you can try GBK or modify the browser's default encoding. ‘‘‘


Python for Chinese encoding processing several ways

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.