Python Lists – Check if any elements are true

In this post we will be creating a Python script that will check whether any items within a list are true, to do this we will be using the ‘any’ function which returns True if any elements within an iterable are true. The ‘any’ function will also return False where the iterable is empty.

See below a list for this example.

List=[False, False, False]

To check whether any items within the list are true we would use the sample of Python code below.

List=[False, False, False]
print(any(List)) 

The above would return ‘False‘ as output. See another example list below where one item has been set to true.

List=[True, False, False]

Running the code below will return ‘True‘ as output.

List=[True, False, False]
print(all(List)) 

Take a look at some of our other content around the Python programming language by clicking here.

Leave a Reply