Tuesday, 9 January 2018

difference between is and == in python

"is" vs "=="
-------------------------
  • "is" expressions evaluate to True if two variables point to the same object.
  • "==" evaluates to True if the objects referred to by the variables are equal.
>>> a = [1, 2, 3]
>>> b = a >>> a is b
True
>>> a == b
True >>> c = list(a) >>> a == c
True
>>> a is c
False

1 comment:

  1. Very informative blog!

    Please take some time to visit my blog @
    Python notes

    Thanks!

    ReplyDelete