4 ms·
Never seen that before. Neat how the bool being a subclass of int pokes out in various ways. A nice side effect is that bools can used with sum: sum(x % 1
by emptysea 6y ago
Never seen that before. Neat how the bool being a subclass of int pokes out in various ways.
A nice side effect is that bools can used with sum:
sum(x % 10 for x in range(1000))
- raziel2p 6y agoBad example? x % 10 does not return a bool.
- emptysea 6y agoWhoops! For future internet historians, it should have been: sum(x % 10 == 0 for x in range(1000))
- eesmith 6y agoIt's not really a bool/int subclass issue but one of hash() and equality. >>> {1} | {1.0} {1} >>> {1.0} | {1} {1.0} >>> import fractions >>> x = fractions.Fraction(1) >>> {x} | {1} {Fraction(1, 1)} >>> {1} | {x} {1}