from itertools import product,takewhile
a = [1,2,3]
b = [1,2,3]
c = [1,2,3]
#嵌套循环,当满足某个条件时执行
for aa,bb,cc in product(a,b,c):
if aa+bb+cc == 9:
print(aa,bb,cc)
#自定义一个方法,返回真则继续,不为真则break
def check_num(num):
if num<3:
return True
return False
for i in takewhile(check_num,a):
print(i)