Home > other >  The output is False. Can someone please explain it?
The output is False. Can someone please explain it?

Time:09-28

The output is False. Can someone please explain it?

a = True
b  = False
print(a == b)

CodePudding user response:

a = True
b  = False
print(a == b)

The print statement looks what to print and encounters a==b which is an expression and not a value and therefore must be evaluated to a value which is then printed. a == b is a request to check if value of a equals to (is the same as) value of b. They are not the same as a==True, but b==False. So the expression/statement a==b is not true, what means that it is False and False is a boolean value and can be printed, so the printed output will be:

False
  • = assigns to the left the value which comes from what is right of it.
  • == compares the value to the left of it to the value to the right of it to check if they are equal and evaluates to (returns) a boolean True if they are and False if they not equal.
  • Related