day03 python learning

Hello ~ Today again share a wave. Today, mainly on the set and character encoding.
A, set
1, is defined: {} in the plurality of elements separated by commas, the plurality of element satisfies the following three conditions must be 1.1 within the set of element types becomes unavailable.
1.2 the unordered collection of elements.
1.3 within the set of elements. no repeat
2, s = {} # default empty dictionary
3, the empty set is defined: S = SET ()
. 4, cast: res = set ( 'hello' ) # { 'h', 'e', 'l ',' L ',' O '}
. 5, built-in method
friends1 = { "ZERO", "Kevin", "Jason", "Egon"}
friends2 = { "of Jy", "Ricky", "Jason", "Egon "}
5.1 on the intersection: a common friend of both
RES = friends1 & friends2 Print (RES) Print (friends1.intersection (friends2))
5.2 and take the set / collection: both all friends
Print (friends1 | friends2)
Print (friends1 .union (friends2))
5.3 set taking the difference: the unique take friends1 friend
Print (friends1 - friends2)
Print (friends1.difference (friends2))
5.4 symmetric difference: find two friends are unique to the user (i.e., to remove common friends) print (friends1 ^ friends2) print (friends1.symmetric_difference (friends2))
Second, the character code
character is a character code table corresponding to the digital relationship tables
python interpreter read the default file encoding
python3 default: UTF-8
python2 default: ASCII
specify the file header to modify the default encoding:
written in the first line of the file py:
coding: GBK
ASCII tables: 1, supports only English strings 2, 8-bit binary number corresponding to an English string
GBK table: 1, supports English characters, Chinese characters 2, 8-bit (8bit = 1Bytes) binary number corresponding to an English string
using (16bit = 2Bytes) 16-bit binary number corresponds to a Chinese string
unicode (unified memory use unicode): 1, compatible character nations, and nations character has a corresponding relationship between the 2, 16-bit (16bit = 2Bytes) binary number corresponds to a Chinese string rare individual will use 4Bytes , 8Bytes
added: garbled text file access problems
exist in turmoil: the solution is, the encoding format should be set within the support file word The format string
takes the chaos: the solution is, what files are encoded formats such as hard disk memory, it should be read into memory for what encoding format

Released five original articles · won praise 2 · views 64

Guess you like

Origin blog.csdn.net/weixin_43138641/article/details/104824895