# Python any(): Powered Up Boolean Function (Summary)

Copied!
Happy Pythoning!

You’ve learned the ins and outs of using `any()` in Python and the differences between `any()` and `or`. You’ve also explored short-circuiting and using list comprehensions with `any()`. With a deeper understanding of these two tools, you’re well prepared to decide between them in your own code.

In this course, you learned how to:

• Use `any()` and `not any()`
• Elimate long `or` chains
• Use `any()` with list comprehensions
• Evalute values that aren’t explicitly `True` or `False`
• Distinguish between `any()` and `or`
• Use short-circuiting

For more information on concepts covered in this course, you can check out:

Sample Code (.zip)

2.0 KB

Course Slides (.pdf)

451.2 KB

deepakpatrick

``````a = [[]]
print(any(a))  # False
a = [[ [] ]]
print(any(a))  # True
``````

The last print output seems counter intuitive

Bartosz Zaczyński RP Team

@deepakpatrick That’s an interesting case! The reason why it’s behaving like this is that an empty sequence is falsy while a non-empty one is truthy:

``````>>> bool([])
False
>>> bool([[]])
True
``````

`any()` iterates over a sequence of values and returns true when there’s at least one truthy value. The `[[]]` sequence contains only one element, which is falsy (`[]`). The other sequence, `[[[]]]`, also contains one element (`[[]]`), but it happens to be non-empty.

to join the conversation.