...

/

What's Wrong With Booleans?

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 = 0
booleans_found_so_far = 0
for item in mixed_list:
if isinstance(item, int):
integers_found_so_far += 1
elif isinstance(item, bool):
booleans_found_so_far += 1
print(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 = True
print("ftw" * some_bool)
some_bool = False
print("ftw" * some_bool)
print("--------")

3.

...