Difference between 'is' and '==' in Python

>>>print(() is () )
True
>>>print(() == ())
True
`````````````````````````````
>>>print([] is [])
False
>>>print([] == [])
True
``````````````````````````
>>>print({} is {})
False
>>>print({} == {})
True
```````````````````````````


can i know difference between "is" and "=="  in above code

In python, == operator compares for the value of two objects, whereas is compares if they’re both the same objects or not.
Here both the objects being compared have same values, but the objects being initialised are different.

For the first line, I’m not sure why is it returning True maybe you can try printing their id and check.
Will get back to you if i find something interesting in this regard.

3 Likes

thank you
for TUPLES (immutable)
both “is” and “==” have same id if the values are same in tuples
but it is not case with list and sets once again thank you for the solution

1 Like