Post

@Python_Dv Answer: A) 2
The boolean arithmetic trap!
› In Python, True = 1 and False = 0
› True + True + False = 1 + 1 + 0 = 2
For beginners: Booleans are a subclass of int and you can use them in arithmetic operations.
English

@Python_Dv The correct answer is A) 2.
In Python, True and False are boolean values that are treated as integers in arithmetic operations. True is equivalent to the integer 1, and False is equivalent to the integer 0. Therefore, the expression True + True + False is
English

@Python_Dv In Python, True = 1 and False = 0. True + True + False = 1 + 1 + 0 = 2
English

@Python_Dv A)2
While I've been using python off and on for years, I've just recently decided to start actually learning to code with it proper. That is to say, I suspected the answer was A or C, so I tried it myself and A was correct. Learning everyday
English

@Python_Dv The output is **2**.
In Python, `True` is equal to `1` and `False` is equal to `0`. The operation is therefore `1 + 1 + 0`, which results in `2`.
English

@Python_Dv A)2
EXPLANATION
in python True has a value of and False has a value of 0.
True + True + False = 1 + 1 + 0 = 2
English

@Python_Dv A. 2.
In python, True and False are categorised as Boolean data types. But in arithmetic operations, they are seen as 1 and 0.
So for the operation above when you substitute 1 and 0 for true and false respectively, the output would be 2.
Because 1 + 1 + 0 = 2.
English

@Python_Dv I’m not a python programmer but i think it’s 2
False = 0
True= 1
English

@Python_Dv A) 2
Because TRUE = 1, FALSE = 0. So TRUE+TRUE+FALSE = 1+1+0 = 2
English

@Python_Dv The answer is A. The reason why the answer is A has already been perfectly explained by my esteemed colleagues.
English

@Python_Dv I read the other comments and tried on REPL as well. But the explanation does not satisfy.
I'd like to ask, if anyone knows *why* this is the case?
+ could easily have been the OR operator, such that True + True = True and True + False = True.
Why does it get converted to int?
English

@Python_Dv It ahould be an error, but Pythonis very permissive. + usually isn't a Boolean operator.
English

@Python_Dv Answer: A
Explanation 👇🏻
Think of True as 1 and False as 0
True + True + False
1 + 1 + 0 = 2
English






















