Just something weird I noticed about the behavior of the all
function, hoping to get a proper explanation of the logic or inner-workings.
Assume I have an empty list - items = []
Normally it would be "falsey", i.e bool(items)
or bool([])
would be False
. However, all
treats it as True
:
all([item for item in items]) # True
all(item for item in items) # True
all(items) # True
all([]) # True
But strangely, having an empty list inside the list, evaluates to false:
all([[]]) # False
This doesn't seem to affect the behavior of any
:
any([item for item in items]) # False
any(item for item in items) # False
any(items) # False
any([]) # False
any([[]]) # False
I've tested it in python 3.7.5, I don't know if this is the behavior in other versions. Can someone please explain this?