Python is Keyword

Example

Check if two objects are the same object:

x = ["apple", "banana", "cherry"]
y = x
print(x is y)

Run Instance

Definition and Usage

The is keyword is used to test if two variables refer to the same object.

If two objects are the same object, then test returns True.

If two objects are not the same object, even if the two objects are 100% equal, test will return False.

Please use the == operator to test if two variables are equal.

More Examples

Example

Test two equal but different objects:

x = ["apple", "banana", "cherry"]
y = ["apple", "banana", "cherry"]
print(x is y)

Run Instance