在Python的for循环里,循环遍历可以写成: for item in list: print item 它可以遍历列表中的所有元素,但是有什么方法可以知道到目前为止我循环了多少次? 想到的替代方案是: count=0 for item in list: print item count +=1 if count % 10 == 0: print 'did ten' 或: for count in range(0,len(list)): print list[count] if count %
a=[str(i) for i in range(88888,88912)] b=[str(i) for i in range(77777,77785)] def f(a,b,k=0,m=0): n=0 g = [] while n<4: j = 0 for i in a[k:]: while j < 1: g.append(i) k = k + 1 j=j+1 break j=0 for i in b[m:]: while j < 2: g.append(i) m = m + 1 j=
for#列表生成式 data = [1,2,3,4,5,6,7] #####列表生成式 #data = [i+1 for i in data] data = [i*2 if i>5 else i for i in data] print(data) data = [i//2 if i>4 else i for i in data] print(data) 1.生成器yield a #返回a,同时挂起当前这个函数yield a #返回a, 同时挂起当前这个函数, a返回给了通过__next__(