The Equality operator (==) compares the values of both the operands and checks for value equality. Whereas the ‘is’ operator checks whether both the operands refer to the same object or not.
Python3
# python3 code to # illustrate the # difference between# == and is operator# [] is an empty listlist1 = []list2 = []list3=list1if (list1 == list2): print("True")else: print("False")if (list1 is list2): print("True")else: print("False")if (list1 is list3): print("True")else: print("False")list3 = list3 + list2if (list1 is list3): print("True")else: print("False") |
Output:
True False True False
- The output of the first if the condition is “True” as both list1 and list2 are empty lists.
- Second, if the condition shows “False” because two empty lists are at different memory locations. Hence list1 and list2 refer to different objects. We can check it with id() function in python which returns the “identity” of an object.
- The output of the third if the condition is “True” as both list1 and list3 are pointing to the same object.
- The output of the fourth if the condition is “False” because the concatenation of two lists always produces a new list.
Python3
list1 = []list2 = []print(id(list1))print(id(list2)) |
Output:
139877155242696 139877155253640
This shows list1 and list2 refers to different objects.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Benefits of Double Division Operator over Single Division Operator in Python
- Difference between != and is not operator in Python
- Operator Functions in Python | Set 2
- Ternary Operator in Python
- Operator Functions in Python | Set 1
- Python | Operator.countOf
- Walrus Operator in Python 3.8
- Python | List comprehension vs * operator
- Check if a value exists in a DataFrame using in & not in operator in Python-Pandas
- Concatenate two strings using Operator Overloading in Python
- What is a modulo operator (%) in Python?
- Operator Overloading in Python
- Python - Star or Asterisk operator ( * )
- What does the Double Star operator mean in Python?
- New '=' Operator in Python3.8 f-string
- Difference between 'and' and '&' in Python
- Python set operations (union, intersection, difference and symmetric difference)
- Difference between Method and Function in Python
- Python | Difference between iterable and iterator
- Difference between List and Array in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
