The Second day in 优快云
I am broken heart.cause I am a loser in the national examination for postgraduate for SJTU
Time is so slow and fast as well
It looks like paradoxical.
Only I can know how about my life
But i will not lose my strong heart.
cease to struggle and cease to live.This is one motto I have learned during my preparation for postgraduate.
yesterday I have read another sentence in bilibili。
Working hard for something we don’t care about is called stress
Working hard for something we love is called passion
To make my work translate into an art
I love my parents,my families and my Alma mater(TJU).
to fight!
well! back to study python
try…except…else
try:
file=open('eeee','r+')
#'r'means only can read
#'r+ means can read and write
except Exception as e:
print(e)
#except Exception as e.Exception means the error information
print('there is no file named as eeeee')
response=input('do you want to create a new file')
if response == 'y':
file=open('eeee','w')
else:
pass
#when we find the error ,we will execute the programe in Exception
#or we will just execute the programe in 'else'
#so in this programe, we don't have the 'eeee' file,
#we will pass and not execute the 'else' below
else:
file.write('ssss')
file.close()
zip_lambda_map
a=[1,2,3]
b=[4,5,6]
#define two lists
print(zip(a,b))
#zip means 数项合并(combine several contracts)
#zip translation:拉链 活力 拉开或拉上 邮编
print(list(zip(a,b)))
#this will get a result:[(1,4),(2,5),(3,6)]
for i,j in zip(a,b):
print(i/2,j*2)
print(list(zip(a,a,b)))
#also can zip 3 contracts
def fun1(x,y):
return(x+y)
print(fun1(2,3))
fun2=lambda x,y:x+y
#lambda can define an anonymous function
fun2(2,3)
map(fun1,[1],[2])
#map can use your function and return the list
#remember it will return a object,not a number
#so you should use list and print
print(list(map(fun1,[1,3],[2,5])))
copy and deep copy
#copy and deepcopy
import copy
a=[1,2,3]
b=a
#id can return the identity of an object
id(a)
id(b)
a[1]=11
print(b)
#we can find that use b=a make programe find a or b in the same location
print(id(a)==id(b))
c=copy.copy(a)
#use copy.copy() can let a浅层数据存储id与b是不一致的,但是深层比如a=[1,2,[3,4]]
#此时id(a[2])==id(b[2])便是Ture
print(id(a)==id(c))
#deepcopy can replicate completely but has different id
threading多线程
#程序分段,共同开始?同时进行多个程序(有劣势)
multi processing
#多核运算(真正的多核分别运算)
tkinter
#可视化窗口
import pickle
#pickle
import pickle
#保存程序运行结果
a_dict={'da':111,2:[23,1,4],'23':{1:2,'d':'sad'}}
file=open('pickle_example.pickle','wb')
#wb means binary file
pickle.dump(a_dict,file)
file.close()
with open('pickle_example.pickle','rb')as file:
a_dict1=pickle.load(file)
print(a_dict1)