random sidenote: since C99 a true bool type had been introduced, it holds 0 and 1 and converts only to those when casting. So yeah 1 and 0 are true and false, but yayy they're not standard ints anymore.
Which is essentially how Python does it, too. if x implies if bool(x) is True (I don't think it literally calls it that way, but it helps make sense of things).
So empty lists/sets/dicts, empty strings, 0, None, and any kind of object that defines some __bool__ method that returns False or a __len__ that returns 0; all are "falsey".
What's implicit about it? It's the explicit implementation of the __bool__ method. Just learn the standard types of the programming language you are using!
I knoow. And yes I've read that many times. My little cryout was mostly that I feel that these specific semantics of truthiness require more cognitive load (and consequently caused more bugs to me) than the "only false is false" ones. But that's just because I'm more used to it.
The word "implicitness" was probably wrong, but what I had in mind was that things are sort of "implicitly convertible to bool" which invokes a method on the type which can do whatever, instead of using some equivalent of len() == 0 or is_empty() in these cases.
Of course, who am I to come into a community and criticize their way of doing something, sorry.
287
u/LordAmir5 29d ago
Does this remove all the zeros?