Python first week (third day) My Python growth is one months to get the Python data mining done! (04)

Source: Internet
Author: User
Tags first string set set stdin

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)

Related Article

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.