摘要: #try...finally 无论是否异常都执行finally#例如实现不管是否异常都输出一串字符串'''try: print ifinally: print "不管上面是否异常,我必须输出"try: i=7 print ifinally: print "不管上面是否异常,我必须输出"'''#实现字 阅读全文
posted @ 2017-06-25 15:49 人间好时节 阅读(2910) 评论(0) 推荐(0) 编辑
摘要: #异常处理#try....except,加入try出现异常,执行xcept部分try: print iexcept NameError:#要指明异常类型 i=9 i+=10 print 'i刚刚没定义,异常处理后i的值为:'+str(i)#多异常处理try: print i+jexcept Name 阅读全文
posted @ 2017-06-25 15:49 人间好时节 阅读(121) 评论(0) 推荐(0) 编辑
摘要: #文件的操作#创建文件fc=open("E:/新建文件夹/a.mp8","w")#参数1表示文件路径以及名称,参数2表示文件的操作方法fc=file("E:/新建文件夹/a.mp9","w")#打开文件fo=open("E:/新建文件夹/a.mp9","w")#若没有此文件open表示创建并打开fo 阅读全文
posted @ 2017-06-25 15:48 人间好时节 阅读(234) 评论(0) 推荐(0) 编辑
摘要: #创建类class man: passprint man#建立实例(对象)class woman: passw=woman()print w 阅读全文
posted @ 2017-06-25 15:47 人间好时节 阅读(138) 评论(0) 推荐(0) 编辑
摘要: #继承实现#父亲会书法,大儿子和小儿子会书法#父亲一般能吃,大儿子吃超过,小儿子吃得少class father: def write(self): print 'i can write'class oldbrother(father):#class A(B)子类A继承父类B def eat(self 阅读全文
posted @ 2017-06-25 15:45 人间好时节 阅读(172) 评论(0) 推荐(0) 编辑
摘要: class woman: passwangdama=woman()lidama=woman()#查看实例的属性#print wangdama.__dict__'''{}'''#为实例添加属性wangdama.toufa='yellow'#print wangdama.__dict__ '''{'to 阅读全文
posted @ 2017-06-25 15:43 人间好时节 阅读(196) 评论(0) 推荐(0) 编辑
摘要: a=int(raw_input('a'))b=int(raw_input('b'))su=[]if a>b: smaller=b else: smaller=a for i in range(1,smaller+1): if a%i==0 and b%i==0: su.append(i)l=len( 阅读全文
posted @ 2017-06-25 15:42 人间好时节 阅读(2419) 评论(0) 推荐(0) 编辑
摘要: a=raw_input('your enter :')l=len(a)su=[]for i in range(0,l): b=a[l-i-1] #print b, su.append(b)print su 阅读全文
posted @ 2017-06-25 15:41 人间好时节 阅读(509) 评论(0) 推荐(0) 编辑
摘要: for i in range(2,1000): s=1 for j in range(2,i): if i%j==0: m=i/j s=s+m if s==i: print i, 阅读全文
posted @ 2017-06-25 15:38 人间好时节 阅读(2457) 评论(0) 推荐(0) 编辑
摘要: #先sorted以从小到大的顺序排列,然后reversed倒转变为从大到小输出,后用+ 链接起来print '+'.join(reversed(sorted('891532')))#同上,以字典形式输出print zip('+'.join(reversed(sorted('891532')))) 阅读全文
posted @ 2017-06-25 15:34 人间好时节 阅读(211) 评论(0) 推荐(0) 编辑