Both “is” and “==” are used for object comparison in Python. The operator “==” compares values of two objects, while “is” checks if two objects are same (In other words two references to same object).
The “==” operator does not tell us whether x1 and x2 are actually referring to the same object or not. We use “is” for this purpose.
No Yes Yes
- “is” returns True if two variables point to the same object.
- “==” returns True if two variables have same values(or content).
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.
- Chaining comparison operators in Python
- Python | Data Comparison and Selection in Pandas
- Python | Excel File Comparison
- Python | Tkinter ttk.Checkbutton and comparison with simple Checkbutton
- Python | Find Hotel Prices using Hotel price comparison API
- Python | Consecutive String Comparison
- Comparison of Python with Other Programming Languages
- Comparison between Lists and Array in Python
- Case-insensitive string comparison in Python
- Python - Similar characters Strings comparison
- String Comparison in Python
- Object Oriented Programming in Python | Set 1 (Class, Object and Members)
- Object Oriented Programming in Python | Set 2 (Data Hiding and Object Printing)
- Comparison of Java with other programming languages
- Python2 vs Python3 | Syntax and performance Comparison
- When to Use Django? Comparison with other Development Stacks
- Python - Read blob object in python using wand library
- OOP in Python | Set 3 (Inheritance, examples of object, issubclass and super)
- pickle — Python object serialization
- Data type Object (dtype) in NumPy 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.