The string involves encoding: ASCII GBK gb2312 Unicode uft-8
For English characters ASCII (can be regarded as a subset of Utf-8), Chinese with gbk/gb2312;
Unicode: The world's unified computer system coding (in memory), but the storage is a waste of space, so save to the hard disk or output to view with uft-8. That is, when you open the reading with Notepad or browse the Web page is unicode-"Tuf-8, Because Notepad and the browser server system are Unicode types
Uft-8:ptthon when saving the source code, it is important to specify Save as UTF-8 encoding. At the beginning of the program, it is stated that UTF-8 encoding does not imply that your .py file is UTF-8 encoded, which is set by the text editor's settings-encoding type to use UTF-8 Without BOM encoding. If the .py file itself uses UTF-8 encoding and also declares # -*- coding: utf-8 -*- , open a command prompt to verify that Chinese is supported
In Python version 3, strings are Unicode-encoded and support Chinese
Python provides a ord(‘字符’) coded integer representation of the function to get the character, and the chr() function converts the encoding to the corresponding character
The string type of Python is a str Unicode representation in memory, a character that corresponds to several bytes, and a Unicode representation of the str pass. encode(‘ASCII’) Method can be encoded as the specifiedbytes
bytesType of data is represented by a b prefixed single or double quotation mark, used for string transmission over the network, or saved to disk
Len (' abc ') and Len (b ' ABC ') represent the number of characters and bytes respectively.
Formatted output: internal and external 22%
>>> ‘Hi, %s, you have $%d.‘ % (‘Michael‘, 1000000) ‘Hi, Michael, you have $1000000.‘
Python Learning character encoding