6.1 small data pool
Python is a small data pool to improve the efficiency of one way, using the same type of fixed data memory address.
Data types supported by the small pool: str, int, bool
id View memory address space, open space acquisition An address
Digital support small data pool range: -5 to 256
Block: a file, a module, a function, a class, a terminal block in each row, in python dictionary is stored.
Analyzing two is the same memory address
== equal sign is determined whether the value of the same
String:
1. multiply string when the overall length of not more than 20, camping
2. string length limit their definition string must not (letters, numbers. Underscore), camping
3. Special characters (Chinese except ) defined a time, to camp
4. The string is actually assigned * 1
If the determination is the same == necessarily the same
if the same is not necessarily the same determination ==
First block of code, do not meet the small data block will
Code block rules:
Digital: all reside
string:
1. multiply the character when the total length can not exceed 20
2. Custom defined reside
3. The multiplier of 1 is assigned when
4.python3.7 multiplying the total length when not over 4096
to sum up:
Decimal pool - support: str, int, bool
small pool of digital data: -5 to 256
small cell string data: multiplying the length of time can not exceed 20
6.2 collection
Collection: set
Dictionary is a collection of no value, follow: unique, unordered, the elements required can hash (immutable) sets are unordered, variable.
Increase: s.update () iteration added.
s.add () to add random
Delete: s.pop () randomly deleted
s.remove () by deleting elements
s.clear () Clear
del s deleted the entire collection
Review: delete, plus
View: for loop
To effect collection of natural weight unique.
s1 = {1,2,3,4,5,6,7}
s2 = {3,4,5,6}
# print(s1 - s2) #差集
# print(s1 | s2) #并集 (合集)
# print(s1 & s2) #交集
# print(s1 ^ s2) #对称差集 -- 反交集
# print(s1 > s2) # 超集 -- 父集
# print(s1 < s2) # 子集
# 冻结集合(可变 转换成 不可变) -- 更不常用
# f_s = frozenset({1,2,3,4,5})
# # dic = {f_s:"1"}
# # print(dic)
6.3 copy depth
Copy - - copy Copy
Assignment - - two variables point to a list of memory addresses.
Assignment instead of copying
Shallow copy: just copy the first layer, will create a new list, the list of elements of the newly created element in the original list and use the same memory space (s.copy ()).
Deep copy: the original list of data types and immutable point to the same space, will create a new variable data space.
import copy
copy.deepcopy()