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