Hello coders, In this tutorial you will learn about “is” keyword in python and will learn how to implement “is” keyword in python with examples.
python “is” keyword is one of the comparison operator used to compare for checking, whether two variables refer two same object or not. The output come in form of boolean value.
If two variables refer to same object then program return true and if two variables not refer to the same object then program return false boolean value.
Now lets try to understand the role of is keyword by implementing it in examples.
x=[1,2,3] y=x x is y
If you run the above code then you will see output as true because both x and y variables refer to same object.
Now let see, the other example of implementing is keyword in python.
x=[1,2,3] y=[1,2,3] x is y
When you run the above code then you will found your output as false because at this time both variable are not refering to the same object.
What is difference Between “is” and “==” in Python?
The difference between “is” and “==” operator is that “is” keyword is used to test if two variables refer to same object or not where “==” operator is used for checking value of two variables.
x=[1,2,3] y=[1,2,3] x is y x==y