defgenerater(num):for i inrange(num):print("开始")yield i
print("生成完成")
g = generater(5)# print(next(g))# print(next(g))# print(next(g))# print(next(g))# print(next(g))# print(next(g))for i in g:print(i)
07_斐波那契数列
# 0, 1, 1, 2, 3, 5, 8, 13, 21, 34deffb(num):
a =0
b =1# 记录生成了几个数字
index =0while index < num:
result = a
#1 1 1 1#1 2 1 2#2 3 2 3
a, b = b, a+b
yield result
index +=1
f = fb(5)# print(next(f))# print(next(f))for i in f:print(i)
08_浅拷贝
import copy
# 1 普通赋值# a = [1, 2, 3]# b = [11, 22, 33]# c = [a, b]## d = c## print(id(d))# print(id(c))# 2 浅拷贝可变类型# a = [1, 2, 3]# b = [11, 22, 33]# c = [a, b]## d = copy.copy(c)## print(id(d))# print(id(c))# 3 浅拷贝-深层数据# a = [1, 2, 3]# b = [11, 22, 33]# c = [a, b]## d = copy.copy(c)## print(id(a))# print(id(c[0]))# print(id(d[0]))# 4 浅拷贝不可变类型
a =(1,2,3)
b =(11,22,33)
c =(a, b)
d = copy.copy(c)print(id(d))print(id(c))
09_深拷贝
import copy
# 深拷贝可变类型# a = [1, 2, 3]# b = [11, 22, 33]# c = [a, b]## d = copy.deepcopy(c)## print(id(c))# print(id(d))# 深拷贝-深层数据# a = [1, 2, 3]# b = [11, 22, 33]# c = [a, b]## d = copy.deepcopy(c)## print(id(a))# print(id(c[0]))# print(id(d[0]))# 深拷贝不可变类型
a =(1,2,3)
b =(11,22,33)
c =(a, b)
d = copy.deepcopy(c)print(id(c))print(id(d))