2.19 2.20 collection 1 / elements inside immutable, you can not exist in the collection list dict, non-numeric strings of similar groups, etc. can be stored becomes 2 / natural weight to 3 / disordered collection can do two things to heavy and relational operators, set intersection and difference set A = {1,2,3,4,2, ' Alex ' ,. 3, ' Rain ' , ' Alex ' } Print (A) { . 1, 2,. 3,. 4, ' Alex ' , ' Rain ' } natural to weight, so that duplicate values are not stored into ---------------------- help to re-list, since the set of natural deduplication Therefore the list to find ways to turn into sets, duplicates removed, reversed in the list Li = [1,2,1,22,3,2,1,4,'rain','alex'] print(li) newli = set(li) print(newli) print(list(newli)) -------------------------------------------- D:\Python\python.exe D:/cc/集合.py [1, 2, 1, 22, 3, 2, 1, 4, 'rain', 'alex'] {1, 2, 3, 4, 'alex', 'rain', 22} [1, 2, 3, 4, 'alex', ' Rain ' , 22 is ] as shown above, the list can be stored a plurality of duplicate values, there is repeated a plurality of values, trying to re-list 1 / through the set into a set list of turn 2 / set in turn as a list - ---------------------------------------- by: the add () A = {. 1, 2,. 3,. 4, ' Alex ' , ' Rain ' } a.add ( . 5 ) a { . 1, 2,. 3,. 4,. 5, ' Alex ' , ' Rain ' } deleted: discard () Note: If a delete value does not exist, no error is not returned data a { . 1, 2,. 3,. 4,. 5, ' Alex ', ' Rain ' } a.discard ( ' Alex ' ) A { . 1, 2,. 3,. 4,. 5, ' Rain ' } POP () to delete random, less, for use in a specific scene a.pop () pop random deleted. since the data amount is too small, the naked eye is called in order to remove the illusion .. . 1 a { 2,. 3,. 4,. 5, ' Rain ' } remove () is similar to discard, but if you delete a value does not exist , will be given. deleted exists no error, but does not return the data a { 2,. 3,. 4,. 5, ' Rain ' } a.remove ( . 1 ) Traceback (MOST Recent Last Call): File" <INPUT> ," ,. 1 Line, in <Module1> a KeyError: . 1 2.20 set relationship calculation s_1024 = { " Page " , " old boy " , " crest " , " horse JJ " , " old village " , " Black girl " , " Alex " } s_pornhub = { " Alex " , " Egon " , "Rain","Ma JJ " , " Nick " , " Jack " } 1 / & intersection intersection () to set 1 and set 2 in the presence of both taken out NOTE: intersection.update () taken out of the results and intersection () the same, but will the original data set back cover taken out .. s_1024 & s_pornhub s_1024.intersection (s_pornhub) { ' Alex ' , ' horse JJ ' } ------------------- -------- 2 / union or collection | Union () merge the two kinds of data, deduplication of s_1024 | s_pornhub s_1024.union (s_pornhub) { ' old village' , ' Rain ' , ' Page ' , ' Egon ' , ' Nick ' , ' black girl ' , ' Alex ' , ' Harbor Heights ' , ' old boy ' , ' Jack ' , ' horse JJ ' } ---- -------------------- 3 / difference-set - . -difference () 1024 If the look created 1024, also created pronhub, not displayed Note: difference_update ( ) results and taken out difference () the same, but will re-cover the original set ..Data is taken out s_1024- s_pornhub s_1024.difference (s_pornhub) { ' old village ' , ' Page ' , ' black girl ' , ' Harbor Heights ' , ' old boys ' } ---------------- --------------- 4 / symmetric difference ^ the symmetric_difference () of the foot 2 T boat out s_1024 ^ s_pornhub s_1024.symmetric_difference (s_pornhub) { ' Egon ' , ' old village long ' , ' Page ' , 'Nick' , ' Black girl ' , ' old boys ' , ' Jack ' , ' Rain ' , ' crest ' } -------------------------- ------------------ 1 / Analyzing two disjoint sets are not, return True or False Print (s_1024.isdisjoint (s_pornhub)) False because really intersect a result, it is returned false 2 / s_1024 determined subset is not s_pornhub returns True or false Print (s_1024.issubset (s_pornhub)) false because 1024 is not a subset pronhub, it returns false . 3 / determination is not a superset of s_1024 s_pornhub returns True orFalse Print (s_1024.issuperset (s_pornhub)) False because 1024 is not pronhub subset, so return False --------------------------- ------------------------ 2.21 binary 1286432168421 What 245 binary is Consideration may be so all of the above add up to 255, (128 * 2) -1 = 255 Therefore, 255-10 = 245 removed 10, then successful 8 + 2 = 10 , 8 and 2 then removed, the result is 11110101 , with the built-in function to look at the results are correct: bin ( 245 ) ' 0b11110101 ' 128 64 32 16 2. 8. 4. 1 . 1. 1. 1. 1. 1 0 0. 1 ----------------------------- - 2.22 character encoding -Text is how to display the ord () each 0 or a 1 bit is occupied spatial units (bits), which represents the smallest computer unit each composed of a 8 bit byte, which is the smallest unit of storage in the computer (after all, you are not half-way to store characters) every eight bits represent a binary character bit bit represents the smallest unit of computer 8bit = 1bytes bytes, the smallest unit of storage, 1bytes abbreviated. IB 1KB = 1024B 1MB = 1024KB 1GB = 1024MB 1TB = 1024GB 1PB = 1024TB 1EB = 1024PB 1ZB = 1024EB 1YB = 1024ZB 1BB = 1024YB --------------------------- -------- 2.26 16 hex 16 hex 10 hex conversion 0 . 1 2. 3. 4. 5. 6. 7. 8. 9 A = 10, B =. 11,, C = 12 is, D = 13 is, E = 14, F. = 15 FFF = 15 (16 ^ 2) + 15 (16 ^. 1) + * 15 (16 ^ 0) = 4095 hex ( 4095 ) ' 0xFFF ' 10 hex 16 hex rotation algorithm except 16 take the remainder to obtain a minimum, and then continue to the quotient of the divided two until the quotient is equal to 0 example: 23612 results hex solution: 23612/16 = 1475.75 take 1475 23 612% 16 = 12 1475/16 = 92 take 92 1475% 16 = 3 92/16 = 5.75 take 5 92% 16 = 12 5/16 = 0.3125 be 0 . 5 16 = 5% see % the result is that line: 0x 5 12 3 12, 12 is therefore equal to c: 0x5c3c hex(23612) '0x5c3c' -------------------------------------------