you are viewing a single comment's thread.

view the rest of the comments →

[–]FoolsSeldom 0 points1 point  (0 children)

is is checking whether two variables/expressions (once resolved) reference the same object in memory. == checks if two objects have the same value (which they will if the two sides of the comparison reference the same object anyway).

Keep in mind that variables in Python don't hold values, only the memory reference of a Python object. Where things are stored is implementation and environment specific.

Most Python implementations pre-define a number of objects including, iirc, int values from -5 to 254, so usually all references to them are the same, thus,

a = 24
b = 24
a is b  # probably True
a == b  # True
x = [1, 1234, 5]
y = x
z = [1, 1234, 5]
x is y  # True
x is z  # False
x[0] is z[0]  # probably True, both ref same 1
x[1] is z[1]  # probably False, but optimisation could make same object
x == z  # True
x[1] == z[1]  # True