The other day on Reddit someone asked this:
Why does
all()
returnTrue
if the iterable is empty? Shouldn’t it returnFalse
just likeif my_list:
would evaluate toFalse
if the list is empty? What’s the thinking behind it returningTrue
?
They have since removed their question, but it sparked a long discussion thread, and my comment was heavily upvoted, so I thought I would record it here:
This is literally a 2,500 year old debate in philosophy. The ancients thought “all unicorns are blue” should be false because there are no unicorns, but modern logic says it is true because there are no unicorns that aren’t blue. Python is just siding with modern predicate logic, but your intuition is also quite common and was the orthodox position until the last few hundred years.
Here is a little more explanation. Western logic is generally thought of as having two main periods: Aristotelean syllogistic logic and modern predicate logic. The classic Aristotelean syllogism runs along the lines of:
- Socrates is a man.
- All men are mortal.
- Therefore, Socrates is mortal.
Logic in the Aristotelean system is centered around statements that all, some, or no X is Y. This creates a square of opposition in which “all men are mortal” contradic