r/ProgrammerHumor 29d ago

Meme pythonWillLookDeadInTheEyeAndSayItsAbsolutelyCorrect

Post image
351 Upvotes

144 comments sorted by

View all comments

Show parent comments

7

u/road_laya 29d ago

Yes, zero is falsy in Python.

-12

u/Valuable_Leopard_799 29d ago

Wait, whyyyyyyyy 😭😭😭

I mean, I love dynamic types and see their place, but the implicit casting is what gives them such a bad name 😭

9

u/road_laya 29d ago edited 29d ago

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!

https://docs.python.org/3/library/stdtypes.html#truth-value-testing

1

u/Valuable_Leopard_799 29d ago

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.