Q. Predict the output:

a, b, c = [1,2], [1, 2], [1, 2]

print (a == b)

print (a is b)


Answer :-

Output:-

True
False

>>>

Explanation :-

(i) (a == b) It will return True because It only check the equity of variables

(ii) (a is b) It will return False because It check is id of  a equal to b.

>>> id(a)
2129212134144
>>> id (b)
2129206394816
>>> 

Here id of a is not equal to id of b.

4 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. Sir why its false you tell me because my exam is near

    ReplyDelete
    Replies
    1. Explanation :-

      (i) (a == b) It will return True because It only check the equity of variables

      (ii) (a is b) It will return False because It check is id of a equal to b.

      >>> id(a)
      2129212134144
      >>> id (b)
      2129206394816
      >>>

      Here id of a is not equal to id of b.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post