Message297268
The truth value of sets is not properly documented, in particular regarding whether an empty set is considered false or not.
Ignoring primitive (such as numerals) as well as user-defined types, https://docs.python.org/3/library/stdtypes.html#truth says:
> The following values are considered false:
>
> - [...]
> - any empty sequence, for example, '', (), [].
> - any empty mapping, for example, {}.
> - [...]
>
> All other values are considered true
According to https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range, a set is not a sequence (it is unordered, its elements do not have indices, etc.):
> There are three basic sequence types: lists, tuples, and range objects.
And, according to https://docs.python.org/3/library/stdtypes.html#mapping-types-dict,
> There is currently only one standard mapping type, the dictionary.
So, as per the documentation, the set type is not a type that can ever be False. However, when I try, bool(set()) evaluates to False.
When I asked this on Stack Overflow, someone checked in the CPython code and judged that this is most likely a mere documentation issue: https://stackoverflow.com/a/44813565/6867099 |
|
Date |
User |
Action |
Args |
2017-06-29 13:36:18 | thomassen | set | recipients:
+ thomassen, docs@python |
2017-06-29 13:36:18 | thomassen | set | messageid: <1498743378.1.0.0570911503542.issue30803@psf.upfronthosting.co.za> |
2017-06-29 13:36:18 | thomassen | link | issue30803 messages |
2017-06-29 13:36:17 | thomassen | create | |
|