Python Tutorial Python Advanced Python References Python Libraries

Python is Keyword



The Python is keyword is used to check whether the two variables belongs to the same object or not. It returns true when the two variables belongs to the same object, else returns false.

Please note that == operator checks if the values of the two variables are equal and is keyword checks if the two variables belongs to the same object.

Example

In the example below, variables x and y are created which belongs to same list object called MyList.

MyList = ['red', 'blue', 'green']

x = MyList
y = MyList

print(x is y)
print(x == y)

The output of the above code will be:

True
True

Example

In the example below, variables x and y are created from different list object called List1 and List2. The is keyword returns false even if the two objects are 100% same.

List1 = ['red', 'blue', 'green']
List2 = ['red', 'blue', 'green']

x = List1
y = List2

print(x is y)
print(x == y)

The output of the above code will be:

False
True

❮ Python Keywords

5