2 ms·
If we do it that way, we have worse problems. if "False": # What do you expect? True or False? print("True") else: print("Fal
by bb88 1y ago
If we do it that way, we have worse problems.
if "False":
# What do you expect? True or False?
print("True")
else:
print("False")
bool() is consistent with how "truthiness" happens in python. Otherwise we end up with the YAML norway problem.
if bool("False"):
print("True")
else:
print("False") # This would be different if we landed here.
And that would be different behavior then the above -- creating a nasty inconsistency.
Honestly it's not that hard to write something that looks like this:
def str_to_bool(val: str) -> bool:
return val.lower() in ["yes", "true", "1"]