0

I have this example:

a = [-10,10][True]
b = [-10,10][False]
print(a,b)# "10 -10"
  • I remember being appalled by this the first time I saw this. But I've gotten used to it. It also means that rather than writing: `if some_boolean: count += 1`, you can instead write `count += some_boolean`. Your opinion of this may vary. – Frank Yellin Oct 23 '20 at 06:45
  • It's also possible to do things such as `some_var=['some_action','some_other_action'][function_that_returns_a_bool()]`, which is more readable, omce you're used to it, than the equivalent if/else boilerplate. – SiHa Oct 23 '20 at 06:51

1 Answers1

0

Since bool is a subclass of int that's why True acts like 1 and False like 0

abhigyanj
  • 2,355
  • 2
  • 9
  • 29