这次只记了没见过的或者我觉得有必要记录一下的
1.文件读取与输出
```
text = 'this is my firsttest.\nthis is next line.\nthisis the last test.'
my_file = open('my_file.txt','w') # w表示write,是写入模式,假如路径中没有此文件,则会自动创建一个
my_file.write(text)
my_file.close()
```
```
file = open('my_file.txt','r') # r表示read,是只读模式
content= file.read()
print(content)
my_file.close()
```
```
file = open('my_file.txt','r') # r表示read,是只读模式
content= file.readlines()
print(content)
my_file.close()
```
上述方法读取后需要以my_file.close()结尾以关闭打开的文件,不妨考虑下面的方法:
with openopen('my_file.txt','r') as file:
content= file.read()
print(content)
2. zip,lambda,map
a = [1,2,3]
b = [4,5,6]
list(zip(a,b))
for i,j in zip(a,b):
print(i/2,j*2)
list(zip(a,a,b))
func = lambda x,y:x+y
list(map(func,[1,3],[2,5]))
3. copy&deepcopy
import copy
a = [1,2,3]
b = a
b[1]=22
print(a)
print(id(a) == id(b))
# 浅复制
a = [1,2,[3,4]]
d = copy.copy(a)
print(id(a) == id(d))
d[0] = 111
print(a)
print(id(a[2]) == id(d[2]))
d[2][1]=444
print(a)
# 深复制
a = [1,2,[3,4]]
c = copy.deepcopy(a)
print(id(a) == id(c))
c[1] = 33
print(c)
print(a)
c[2][1] = 333
print(c)
print(a)