What's Wrong With Booleans?
We'll cover the following...
Booleans were supposed to be straightforward: true or false. But, are they?
1.
Below is a simple example to count the number of booleans and integers in an iterable of mixed data types.
Press + to interact
mixed_list = [False, 1.0, "some_string", 3, True, [], False]integers_found_so_far = 0booleans_found_so_far = 0for item in mixed_list:if isinstance(item, int):integers_found_so_far += 1elif isinstance(item, bool):booleans_found_so_far += 1print(integers_found_so_far)print(booleans_found_so_far)
2.
What do you think the output of the following code will be?
Press + to interact
some_bool = Trueprint("ftw" * some_bool)some_bool = Falseprint("ftw" * some_bool)print("--------")