all()函數和any()函數可以應用到一個鏈表或者其它序列,以檢查是否全部或任一項目滿足一些條件。
sent = ['No', 'good', 'fish', 'goes', 'anywhere', 'without', 'a', 'porpoise', '.']
print(all(len(w) > 4 for w in sent)) # 返回False
print(any(len(w) > 4 for w in sent)) # 返回True
all()函數和any()函數可以應用到一個鏈表或者其它序列,以檢查是否全部或任一項目滿足一些條件。
sent = ['No', 'good', 'fish', 'goes', 'anywhere', 'without', 'a', 'porpoise', '.']
print(all(len(w) > 4 for w in sent)) # 返回False
print(any(len(w) > 4 for w in sent)) # 返回True
1.while循環的格式 while 條件: 條件滿足時,做的事情1 條件滿足時,做的事情2 條件滿足時,做的事情3 ...(省略)... demo