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
deffunc1():
print‘helloworld‘
res=func1()
printtype(res)
deffunc2():
return[‘xyz‘,10000,-98]
atuple=func2()
x,y,z=func2()
printx,y,z
deffunc3():
return‘xyz‘,1000,-98
x,y,z=func3()
printx,y,z
deffunc4():
return[‘xyz‘,1000,-98,‘xxx‘]
x,y,z,d=func4()
alist=x,y..
分类:
编程语言 时间:
2016-06-23 19:02:35
阅读次数:
256
require:只加载一次,后面不会执行dofile:每一次文件都会执行loadfile:载入后不执行,等你需要的时候执行时localHaosModel={}
localfunctiongetname()
return"HaoChen"
end
functionHaosModel.Greeting()
print("Hello,Mynameis"..getname())
end
localhao_model=require..
分类:
其他好文 时间:
2016-06-23 19:02:06
阅读次数:
196
deffunc1():
dict1={}
dict2={‘name‘:‘earth‘,‘port‘:80}
returndict1,dict2
deffunc2():
returndict(([‘x‘,1],[‘y‘,2]))
deffunc3():
adict={}.fromkeys([‘x‘,‘y‘],23)
returnadict
deffunc4():
alist={‘name‘:‘earth‘,‘port‘:80}
forkeysinalist.keys():
print"%s%s"%(key..
分类:
编程语言 时间:
2016-06-23 19:01:39
阅读次数:
236
foo=‘abc‘
foriinrange(len(foo)):
print"%d,%s"%(i,foo[i])
print[x**2forxinrange(5)ifnotx%2]
try:
f=open(‘e:\XIN_370_logic.tx‘,‘r‘)
foreachlineinf:
printeachline
f.close()
exceptIOError,e:
printe
deffunc1(x):
returnx+x
x=[iforiinrange(4)]
printfunc1(x)
deffun..
分类:
编程语言 时间:
2016-06-23 19:01:28
阅读次数:
209
deffunc1():
alist=[‘Cathy‘,‘Terry‘,‘Joe‘,‘Health‘,‘Lucy‘]
foriinrange(-1,-len(alist)-1,-1):
printi,alist[i]
deffunc2():
alist=[‘Cathy‘,‘Terry‘,‘Joe‘,‘Health‘,‘Lucy‘]
fori,nameinenumerate(alist):
print‘%d%s‘%(i,name)
importrandom
deffunc3():
alist=[‘Cathy‘..
分类:
编程语言 时间:
2016-06-23 19:01:02
阅读次数:
234
实例1functionnewCounter()
locali=0--方法里的i变量不会被销毁
returnfunction()--anonymousfunction
i=i+1
returni
end
end
c1=newCounter()
print(c1())-->1
print(c1())-->2实例2functionmyPower(x)
returnfunction(y)returny^xend
end
power2=myPower(2)--power2..
分类:
其他好文 时间:
2016-06-23 19:00:17
阅读次数:
179
classAddrBookEntry(object):
‘addressbookentryclass‘
def__init__(self,nm,ph):
self.name=nm
self.phone=ph
print‘createdinstancefor:‘,self.name
defupdatephone(self,newph):
self.phone=newph
print‘updatephonefor:‘,self.name
defupdatename(self,newname):
self.name..
分类:
编程语言 时间:
2016-06-23 18:59:59
阅读次数:
203
1、首先执行命令,写到1.log文件下面: find -name '*.rdb'|xargs stat| grep -i Modify | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{ ...
分类:
其他好文 时间:
2016-06-23 12:36:25
阅读次数:
208
echo()可以一次输出多个值,多个值之间用逗号分隔。echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用。print()函数print()打印一个值(它的参数),如果字符串成功显示则返回true,否则返回false。print_r()可以把 ...
分类:
其他好文 时间:
2016-06-23 08:49:40
阅读次数:
189