随笔分类 -  python

摘要:#反转过程def add(x,y): return x+yparams = (1,2)add(*params)#3def story(**kwds): return 'Once upon a tinme,there wa s '\ '%(job)s called %(name)s' %kwsdef power(x,y,*others): if others: print 'Received redundat parameters:',others return pow(x,y)def interval(start,stop=None,... 阅读全文
posted @ 2013-06-29 21:19 我叫龙弟弟 阅读(168) 评论(0) 推荐(0)
摘要:#callback 判断是否存在import matchx = 1y = math.sqrtcallable(x)#Falsecallable(y)#True#函数def fib(num): result = [0,1] for i in range(num-2): result.append(result[-2],result[-1]) return result;fibs(10)#[0,1,1,2,3,5,8,13,21,34]#函数文档def square(x): 'Calcutates the square of the number x'... 阅读全文
posted @ 2013-06-29 20:22 我叫龙弟弟 阅读(199) 评论(0) 推荐(0)
摘要:#字符串操作#example1 字符串截取strs = '123456789'print strs[0:1] #1 输出0到1的字符print strs[1:6]#23456 输出1~6的字符串num = 18strs = '00000' + str(num) #合并字符串print strs[-5:]#00018 输出字符串右5位#example2 字符串替换str = 'akakak'str = str.replace('k',8) #将字符串里的卡全部替换成8print str#'a8a8a8'#exampl 阅读全文
posted @ 2013-06-26 20:11 我叫龙弟弟 阅读(199) 评论(0) 推荐(0)