String STR and Unicode
STR byte stream
Unicode character stream (Chinese, English, etc.) how do I convert to 01 code in a computer?
Encoded ASCII, iso88591, UTF8 (after Unicode compression), Unicode (one character encoded in four bytes), UTF32, gb2312, etc.
So how does GBK convert into UTF8?
GBK, Unicode-UTF8
decoding, encoding
Unicode-UTF8 encoding
gbk-> Unicode decoding
Solve the coding problem:
Import Sys
Print sys.stdin.encoding
Print sys.stdout.encoding
x = raw_input (U ' Please enter name: '. Encode (sys.stdout.encoding)) # First String ' Please enter first name: ' For Unicode decoding, and then encoded in sys.stdout.encoding way
f = open (' 1.txt ', ' W ')
F.write (X.decode (sys.stdin.endcoding). Encode (' Utf-8 ') # First decodes the input characters in sys.stdin.endcoding mode and then encodes them with utf-8
F.close ()
Dictionary Dict
The key is hashed into a number, as the array subscript, time complexity is constant
Key is immutable, numbers, strings, tuples can be a key, the list is not a key can be hash can be used as key
Key in Dict determine if there is a key in the dictionary
Common operations:
For key, value in X.items ():
Print key, ' = ', value
Print x.get (' name ', ' not present ')
Print X.setdefault (' Naem ', ' 20 ')
Print X.keys (), X.values ()
X.update ({1: ' A ', 2: ' B ', 3: ' C '}) #参数中的字典会更新x的值, no then insert, overwrite
X.clear ()
Collection:
Collections are unordered, non-repeating, elements are immutable, index and slice operations are not supported
Variable Set Set
Immutable Collection Frozenset
Create a collection: Using the Factory function set () and Fronzenset () parameters are generally list
Set Operations: | & - ^ |= < > s.isdisjoint (t)
and the intersection of the symmetric difference set and whether the subset is a superset
Python first week (third day) My Python growth is one months to get the Python data mining done! (04)