所有的程序员都是编剧,所有的计算机都是烂演员。   
返回顶部
摘要: 一、什么是生成器? 答:当函数体内有yield的关键字时就叫做生成器 可以看出 1、生成器就是迭代器 2、yield与return一样 都是返回值 (区别?向下继续看) 既然生成器就是迭代器 那就可以用for循环来实现一下这个 二、yield的功能 1、把函数的最后执行结果做成迭代器 2、yield 阅读全文
posted @ 2018-07-24 10:41 steven丶syw 阅读(217) 评论(0) 推荐(0)
摘要: 1、for循环工作原理: for循环: 原理:for循环其实就是再调后面那个d的d.__iter__() 2、while循环 这段代码会报异常如下图: 这时 你就会用到 try和except(捕捉): 步骤 :(1) 、 首先建立一个while循环 (2)、 再循环里建一个try语法 (3)、 将循 阅读全文
posted @ 2018-07-21 08:04 steven丶syw 阅读(163) 评论(0) 推荐(0)
摘要: 什么是迭代器? 答:重复,下一次的输出是基于上一次的结果 列子: i=[1,2,3,4] count=0 while count<len(i): print(i[count]) count+=1 索引 i={'a':1,'b':2,'c':3} for k in i: print(k) 通常以前都会 阅读全文
posted @ 2018-07-19 10:24 steven丶syw 阅读(135) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2018-05-18 14:04 steven丶syw 阅读(150) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2018-05-18 14:02 steven丶syw 阅读(207) 评论(0) 推荐(0)
摘要: a=1 def foo(): a=2 def foo2(): print(a) return foo2 y=foo() y() 包三层 def egon_name(): name='Steven' def monthly_pay(): money = 100000 def hehe(): print 阅读全文
posted @ 2018-05-13 12:16 steven丶syw 阅读(129) 评论(0) 推荐(0)
摘要: 1、global:在局部修改全局变量 x=100 def foo(): global x x=200 foo() print(x) #todo 如果不写global,则打印为100 2、nonlocal:只在函数内部找变量,如果没有则报错 x=100 def a(): x=200 def b(): 阅读全文
posted @ 2018-04-26 18:22 steven丶syw 阅读(161) 评论(0) 推荐(0)
摘要: 1、可引用 def foo(): return ('hello world!') a=foo print(a()) 2、可当返回值 def outer(): def inner(): print(111) return inner y=outer() y() #todo 如果将111改为inner 阅读全文
posted @ 2018-04-25 23:40 steven丶syw 阅读(199) 评论(0) 推荐(0)
摘要: a=1 def foo(): print(a) def foo2(): print(a) foo2() def foo3(): print(a) foo() foo3() def x1(): #todo 从内往外看 a=10 def x2(): a=20 def x3(): a=30 print(a 阅读全文
posted @ 2018-04-23 19:27 steven丶syw 阅读(181) 评论(0) 推荐(0)
摘要: a=10 def foo(): print(a) foo() # def foo2(a,b): # c=1 # print(a,b,c) # foo2(10,9) a=10 def foo1(): a=20 print(a) foo1() # 因为局部有一个值 所以打印为20 b=10 def fo 阅读全文
posted @ 2018-04-22 19:57 steven丶syw 阅读(176) 评论(0) 推荐(0)