- 2

Boolean

My question is: how did "boolean" values become "integer" according to the output below. a = 1 > 2 b = 5 > 4 c = 1 > 0 d = a + b + c print(a , b, c, d) #output: False True True 2 print(type(d)) # output: <class 'int'>

21st Sep 2021, 9:17 PM
Bekir
Bekir - avatar
2 Respostas
+ 4
bool(x) ----> x for every float and integer numbers but not 0 would be True and for 0 would be False So if 5>2 it's true and for True it would be 1 And if 2>7 it's false and for false it would be 0 ! boolean has only two bits(0,1) and includes binary numbers which includes 0 and 1 , 0 for false and 1 for true so boolean has only two bits : 0 and 1
21st Sep 2021, 10:24 PM
Amirreza
Amirreza - avatar
+ 1
The values of true and false are 1 and 0 orderly. So, true + true = 1+ 1 = 2. Happy coding!
21st Sep 2021, 9:31 PM
mesarthim
mesarthim - avatar