摘要: 1.abs(),取绝对值 2.all(),判断里面是否都为真 def all(iterable) for element in iterable if not element: return False return True 3.any(),判断里面元素是否有真 4.ascii(object) 忘 阅读全文
posted @ 2017-11-14 18:06 仔仔爱python 阅读(132) 评论(0) 推荐(0) 编辑
摘要: import time def consumer(name): print("%s 准备吃包子啦!"%name) while True: baozi = yield print("包子[%s]来了,被[%s]吃了!"(baozi,name)) def producer(name) c = consu 阅读全文
posted @ 2017-11-12 17:11 仔仔爱python 阅读(94) 评论(0) 推荐(0) 编辑
摘要: 首先之前学了函数 显示函数的形式: def fib(max): n,a,b = 0,0,1 while n < max print(b) a,b = b,a+b n = n+1 return 'done' f = fib(10) print(f) 这时候,这一串代码代表一个函数,fib(max)代表 阅读全文
posted @ 2017-11-12 15:58 仔仔爱python 阅读(923) 评论(0) 推荐(0) 编辑
摘要: 通过列表生成器,我们可以直接创建一个列表,但是由于受到内存限制,列表容量肯定是有限的,而且,创建一个包含100万个元素的列表,不仅占用很大的储存空间,如果我们仅仅需要访问前面几个元素的话,后面元素占用的空间都白白浪费了。 所以,如果列表元素可以按照某种算法推算出来,那么我们是否可以在循环的过程中不断 阅读全文
posted @ 2017-11-12 00:06 仔仔爱python 阅读(611) 评论(0) 推荐(0) 编辑
摘要: import time user,passwd = 'zaizai','abc123' def auth(auth_type): print("auth func:",auth_type) def outer_wrapper(func): def wrapper(*args,**kwargs) pr 阅读全文
posted @ 2017-11-11 17:29 仔仔爱python 阅读(186) 评论(0) 推荐(0) 编辑
摘要: import time def timer(func): def deco(arg1): start_time=time.time() func(arg1) stop_time=time.time() print("the func run time is %s"%(stop_time-start_ 阅读全文
posted @ 2017-11-09 18:50 仔仔爱python 阅读(132) 评论(0) 推荐(0) 编辑
摘要: import time def deco(func): start_time=time.time() func() stop_time=time.time() print("the func run time is %s"%(stop_time-start_time)) def test1(): t 阅读全文
posted @ 2017-11-09 16:59 仔仔爱python 阅读(157) 评论(0) 推荐(0) 编辑
摘要: 这节主要分析两串代码 x=0 def grandpa(): x=1 def dad(): x=2 def son(): x=3 print (x) son() dad() grandpa() 这其实是一个3个函数的嵌套,首先定义了一个grandpa这个函数,后面的几行是他的函数体,最后一行代表运行函 阅读全文
posted @ 2017-11-08 15:52 仔仔爱python 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 高阶函数分为两种: a:把一个函数名当做实参传给另一个函数(在不修改被装饰函数源代码的情况下为其添加附加功能) b: 返回值中包含函数名(不修改函数的调用方式) a: 第一个代码: def bar(): print('in the bar') def test1(func): func() test 阅读全文
posted @ 2017-11-05 22:18 仔仔爱python 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 装饰器: 定义:本质是一个函数,装饰其他的函数,就是为其他函数添加附加功能。 原则:1.不能修改被装饰的函数的源代码 2.不能修改被装饰的函数的调用方式 实现装饰器的知识储备: 1.函数即“变量” 2.高阶函数 3.嵌套函数 高阶函数+嵌套函数=》装饰器 装饰器的一个例子: import time 阅读全文
posted @ 2017-11-04 15:58 仔仔爱python 阅读(104) 评论(0) 推荐(0) 编辑