Python – Difference Between “is” and “==” (double equals)

Python - Difference Between is and double equals

This may be a point where a lot of you may get confused. I see some people using them in if conditions without actually knowing what they do. Let me try to explain the concept with a couple of lines of code…

See the code below and try to guess what is printed as the output:

Here is the output:

Explanation:

1- “==” will check if the contents of the lists are the same, including the order.

2- “is” will check if the lists are the same list. Meaning the exact same list in the memory!

3- “list4 = list1” makes list4 point to the same list as list1 in the memory. If we edit list1 and print list4 we will get the same result as we were printing list1.