码迷,mamicode.com
首页 >  
搜索关键字:def    ( 28626个结果
平方回文素数
程序地址:http://www.cheemoedu.com/exercise/24问题描述:素数的平方是回文,比如11*11=121。求不超过1000的平方回文素数。我的代码:importmath defprime(m): count=0 foriinrange(2,int(math.sqrt(m))+1): ifm%i==0: count=1 ifcount!=1: returnTrue else: returnFalse def..
分类:其他好文   时间:2016-06-25 15:09:39    阅读次数:131
装饰器
def outer(func): def inter(): print('befor') func() print('after') return inter @outer def f1(): print('F1') 结构:@+函数名 功能: 1.遇到@时自动执行outer函数,并将其下面的函数f1 ...
分类:其他好文   时间:2016-06-25 12:28:25    阅读次数:269
面向对象(上)
def Bar(self): print 'Bar' def Hello(self, name): print 'i am %s' %name # 根据类Foo创建对象obj obj = Foo() obj.Bar() #执行Bar方法 obj.Hello('123') #执行Hello方法 面向对 ...
分类:其他好文   时间:2016-06-25 11:01:15    阅读次数:143
python 批量修改图片大小
# -*- coding: utf-8 -*- import os import glob from PIL import Image import os.path '''修改图片文件大小jpgfile:图片文件;savedir:修改后要保存的路径''' def convertjpg(jpgfile ...
分类:编程语言   时间:2016-06-24 18:41:17    阅读次数:215
【一天一道LeetCode】#98. Validate Binary Search Tree
一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder‘s Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is def...
分类:其他好文   时间:2016-06-24 15:39:57    阅读次数:147
day7
1、python 函数式+面向对象2、函数式编程,面向对象编程实现:发送邮件的功能 # 函数 def mail(email, message): print("去发吧") return True mail("alex3714@126.com", "好人") 面向对象:类,对象 class Foo: ...
分类:其他好文   时间:2016-06-24 12:21:45    阅读次数:288
html_01
HTML:浏览器与服务器之间通信 web: import socket def handle_request(client): buf = client.recv(1024) client.sendall(bytes("HTTP/1.1 201 OK\r\n\r\n","utf8")) client ...
分类:Web程序   时间:2016-06-24 12:15:59    阅读次数:241
Python成生随机KEY工具
#-*-coding:utf-8-*- fromPyQt4.QtCoreimportpyqtSignature fromPyQt4.QtGuiimportQDialog fromPyQt4importQtGui,QtCore fromUi_CreateKeyimportUi_CreateKey importbase64,uuid classCreateKey(QDialog,Ui_CreateKey): def__init__(self,parent=None): QDialog.__init__(self..
分类:编程语言   时间:2016-06-23 22:31:27    阅读次数:321
Python基础学习代码之序列
str1=‘abced‘ foriinrange(-1,-len(str1),-1)+[None]: printstr1[:i] s,t=‘abc‘,‘def‘ printzip(s,t) fori,tinenumerate(str1): printi,t printisinstance(‘foo‘,str) importstring defcheckid(): alphas=string.letters+‘_‘ nums=string.digits check=raw_input(‘inputid..
分类:编程语言   时间:2016-06-23 19:04:11    阅读次数:391
Python基础学习代码之执行环境
classC(object): def__call__(self,*args,**kwargs): print"I‘mcallable!calledwithargs:\n",args c=C() c(‘a‘,1) single_code=compile("print‘hello,world!‘",‘‘,‘single‘) exec(single_code) eval_code=compile(‘100*3‘,‘‘,‘eval‘) printeval(eval_code) #exec_code=compile..
分类:编程语言   时间:2016-06-23 19:02:36    阅读次数:219
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!