Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: all() & any()

📅 2009-Oct-21 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ all, any, python ⬩ 📚 Archive

all(iterable) returns True if all elements in iterable are True for “if element:”

# any(iterable) returns True if any element in iterable is True for "if element:"

alist = [True, True, True]
all(alist) # True
any(alist) # True

blist = [True, 0, 1, "True"]
all(blist) # False, due to 0
any(blist) # True

clist = [True, 1, "False"]
all(clist) # True
any(clist) # True

dlist = [False, 0, [], None]
all(dlist) # False
any(dlist) # False

© 2022 Ashwin Nanjappa • All writing under CC BY-SA license • 🐘 @codeyarns@hachyderm.io📧