I want to show that it returns False, man.
When you see, that the whole express can be replaced with semantically equivalent construction, it’s not necessary because it’s written by a moron who can’t see that :)
[link](https://stackoverflow.com/questions/715417/converting-from-a-string-to-boolean-in-python)
A freaking gold mine of everything from "why don't you just use an if else" to "here is this obscure module that has this one function that does it.", To "have you tried converting to Json or yml first?" And "here is a depreciated std library function from the depths of hell that performs an if else for you"
The top answer gives a really great into what's going on though:
>Empty strings evaluate to False, but everything else evaluates to True. So this should not be used for any kind of parsing purposes.
This makes perfect sense. That "bool()" constructor doesn't **parse** strings, it **converts** them. It is very logical for non-zero values to be converted to True. If your string is "False" or "0" or "zero" or "nope", all this constructor sees is that it has contents and hence is non-zero.
If you go in with the assumption that it will interpret the contents of your string, I can understand that you get stuck for hours on an issue like this. Easy mistake to make, even for experienced programmers.
I’m really curious, why are booleans stored in string format such a common problem for people? This is something I maybe encountered once, and never in any sort of realistic scenario.
11 Comments
madbirdribdam@reddit
smog29@reddit
madbirdribdam@reddit
Immediate-Win-3043@reddit
zyygh@reddit
vlsdo@reddit
anonymoussphenoid@reddit
er3z7@reddit
cs12345@reddit
misingnoglic@reddit
nemo24601@reddit