Definition:
When you use identity operators (is, is not) in your program, they check whether two variables refer to the same object or not.
whereas,
is – It checks if two variables are the same; you will use the 'is' operator.
is not – It checks if two variables are not the same; you will use the 'is not' operator.
Now you will clearly understand through the flowchart .
a = [11, 2] b = a a ───► [11, 2] ◄─── b Check: a is b → True a is not b → False
Syntax
var1 is var2
var1 is not var2
Example:
a = [11, 2]
b = a
print(a is b)
print(a is not b)
Output:
Exercise
Check whether the variables a and b refer to the same object or not.
a = [11, 2]
b = a
