The == operator compares the values of both the operands and checks for value equality. Whereas is operator checks whether both the operands refer to the same object or not.
True False True False
- Output of the first if condition is “True” as both list1 and list2 are empty lists.
- Second if 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.
- Output of the third if condition is “True” as both list1 and list3 are pointing to the same object.
- Output of the fourth if condition is “False” because concatenation of two list is always produce a new list.
This shows list1 and list2 refers to different objects.
- Benefits of Double Division Operator over Single Division Operator in Python
- Operator Functions in Python | Set 1
- Python | Operator.countOf
- Ternary Operator in Python
- What is a modulo operator (%) in Python?
- Operator Functions in Python | Set 2
- Walrus Operator in Python 3.8
- Operator Overloading in Python
- Python | List comprehension vs * operator
- Concatenate two strings using Operator Overloading in Python
- Check if a value exists in a DataFrame using in & not in operator in Python-Pandas
- Python set operations (union, intersection, difference and symmetric difference)
- Difference between C and Python
- Difference between Python and C#
- Difference between 'and' and '&' in Python
- Difference between Python and C++
- Python Set | difference()
- Difference Between x = x + y and x += y in Python
- Difference between dir() and vars() 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 firstname.lastname@example.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.
Improved By : XAkash