day2_python_learn for mofan

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,[13],[25])))

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值