Python all() Function

Example

Check if all items in the list are True:

mylist = [True, True, True]
x = all(mylist)

Run Example

Definition and Usage

If all items in the iterable are true, the all() function returns True, otherwise it returns False.

If the iterable is empty, the all() function also returns True.

Syntax

all(iterable)

Parameter Value

Parameter Description
iterable Iterables (lists, tuples, dictionaries)

More Examples

Example

Check if all items in the list are True:

mylist = [0, 1, 1]
x = all(mylist)

Run Example

Example

Check if all items in the tuple are True:

mytuple = (0, True, False)
x = all(mytuple)

Run Example

Example

Check if all items in the set are True:

myset = {0, 1, 0}
x = all(myset)

Run Example

Example

Check if all items in the dictionary are True:

mydict = {0 : "Apple", 1 : "Orange"}
x = all(mydict)

Run Example

Note:When used on a dictionary, the all() function checks all keys are true, not the values.

Related Pages

Reference Manual:any() Function