Python is Keyword
The is keyword is used to determine if two variables reference the same object.
Example
Python
Copy Code
a = 1 b = 1 if (a is b): print("a is b") else: print('a is not b')
Output
a is b
Do not use the is
operator to determine of the value of two objects are equal. Use the ==
operator instead.
Example
Python
Copy Code
array1 = [1, 2, 3] array2 = [1, 2, 3] myArray = array1 if array1 is array2: print('array1 is array2') else: print('array1 is NOT array2') if array1 == array2: print('array 1 equals array 2') if myArray is array1: print('myArray is array1')
Output
array1 is NOT array2 array 1 equals array 2 myArray is array1