3 ms·
The very first example is stupid. What sane language would assume a non-empty string should be converted to a False boolean?
by hueving 11y ago
The very first example is stupid. What sane language would assume a non-empty string should be converted to a False boolean?
- msane 11y agoisn't it doing the opposite? str(False) is the string "False", which bool() casts to True because it is a non-empty string; Non-empty strings are cast to True booleans. This is much faster than checking if the string has some semantic meaning first, which would have to be localized.
- ketralnis 11y agoThat's exactly what the grandparent is saying