3

I'm currently having a hard time understanding why the output of

1 is not '1' == True

is

False

The thing is when I'm inserting brackets like that:

1 is not ('1' == True)
(1 is not '1') == True

both return True.

I get the second part, because 1, which is True, is not False, which is the result of the comparison of the string "1" and True. Furthermore, the integer 1 is not the string one, which is true and therefore equal to True. But as soon as I do not put any bracket, it returns False. Why is that?

Thomas
  • 75
  • 8

1 Answers1

0

is is used to compare address(reference) while == is used t o compare values. Therefore 1 is not '1' == True is always False

As @deceze mentioned, here is the second part:

>>> 1 is not ('1' == True)
>>> ('1' == True)
>>> False
>>> 1 is not False
>>> True

>>> (1 is not '1') == True
>>> (1 is not '1')
>>> True
>>> True == True
>>> True
akash karothiya
  • 5,736
  • 1
  • 19
  • 29