3 ms·
prefer bool() threw an exception on receiving a string, rather than act the way it does now. That breaks the truthiness cornerstone of the language. You can wr
by 3eb7988a1663 1y ago
prefer bool() threw an exception on receiving a string, rather than act the way it does now.
That breaks the truthiness cornerstone of the language. You can write
a = 1 # or [], (), "yo", "false", 3.2, MyFooClass(), (1,), False
if a:
fire_ze_missles()
else:
declare_peace()
Upon encountering `a`, Python is evaluating bool(a). If that no longer works for strings, you now need a separate code path for determining a non-empty string.
It can short-circuit the brain upon reading a word that you know means false, but the Python rules are consistent. "Empty" is False, everything else is True.
- moffkalast 1y agoYou can write that yes, but I'm calling the police.
- jonathrg 1y agoYou can't go calling the police on people for writing idiomatic Python code.